---학습과정------------------
jsp기본문법(1)
-스크립트요소
-선언문
변수선언
-스크립트릿
-스크립트릿의 활용
-표현식의 활용
-주석
-jsp의 기본 제어문
if-else(조건 분기문)
for(반복문)
while(반복문)
------------------------------ :::82.ScriptExample1.jsp ::::::::::::::::::::::::::::::::::::::::::::::
Script Example1 <%! String declaration = Declaration; %> file://<%! ~ %>: 선언부입니다 <%! public String decMethod(){ file://메소드생성 return declaration; file://declaratin은 값을 리턴 } %> file://04:~ 12: 묶어서 사용가능 <% String scriptlet = Scriptlet; String comment = Comment;
out.println(내장객체를 이용한 출력 : + declaration + ); file://웹브라우저에서 출력 %> file://선언부가 아니라 jsp영역으로
선언문의 출력1 : <%=declaration%>
선언문의 출력2 : <%=decMethod()%>
file://declaration을 출력 스크립트릿의 출력 : <%=scriptlet%>
<%-- JSP 주석2 : <%=comment%> --%> <% /* 주석 (여러줄 주석) */ %> <%// 주석(한줄 주석)%>
[Note] *웹서버가동중인지 확인 1.C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\ch04\ 작업한파일.jsp 2.웹브라우저 띄운다(client) 3.요청 http://localhost:8080\ch04\jsp파일명 4.주석확인 - [차이--소스보기] -jsp의 주석확인
*내용 <%! ~ 는 선언 <%= ~ 는 출력 <%-- ~ 는 주석
* <%! int cnt1; %> <% int cnt2; <%= cnt %> <%= cnt2 %>
:::86.Declaration Example1 ::::::::::::::::::::::::::::::::::::::::::::::
Declaration Example1 <% String name = team + Fighting!!!; %> file://멤버변수는 아무곳이나 선언해도 됨 <%! String team = Korea; %> file://선언부 출력되는 결과는 ? <%=name%>
:::87.Declaration Example2.jsp ::::::::::::::::::::::::::::::::::::::::::::::
Declaration Example2 file://멤버변수는 초기화하지 않았도 자동초기화된다. <%! int one; int two = 1; public int plusMethod(){ return one + two; } String msg; int three; %>
one 와 two의 합은 ? <%=plusMethod()%>
file://호출리턴 String msg의 값은 ? <%=msg%>
file://초기화 null int three의 값은 ? <%=three%> file://three은 `0`으로 초기화
:::90.Scriptlet Example2.jsp ::::::::::::::::::::::::::::::::::::::::::::::
Scriptlet Example2 <% float f = 2.3f; file://2.3f ->기본형-반올림 file://참고 file://float f는 변수 = 2.3f은 상수; file://실수는 자동으로 dooble형 int i = Math.round(f); java.util.Date date = new java.util.Date(); %> 실수 f의 반올림값은? <%=i%>
현재의 날짜와 시간은? <%=date.toString()%> file://toString :문자형변화 [Note] <%@ page ~ %> <%@ :지시부 <%! :선언부 <%= :표현, 출력 <%-=%> <%-- --%> <%@ page impoet=Java.util*,Java.awt* %>
:::92.Expression Example1.jsp ::::::::::::::::::::::::::::::::::::::::::::::
Expression Example1 <%! String name[] = {Sun,Java,JSPStudy}; file://세개의 배열성공 file://*name이라는 배역변수를 선언과 동시에 값을 부여 하였습니다. %>
<% for (int i=0;i file://*정수 i가 배열의 길이만큼 for문을 루프로 돌려서 출력합니다.
<%=i%> |
<%=name[i]%> |
<%}%>
file://위상단소스 중요도***** file://게시판...많이쓰임
:::92.Expression Example2.jsp ::::::::::::::::::::::::::::::::::::::::::::::
Expression Example2 <% java.util.Date date = new java.util.Date(); int hour = date.getHours(); file://getHours은 시간만 담고 file://음영 : Date 클래스에서 getHours() 메소드를 사용하여 시간(hour) 값만 반환을 합니다. int one = 10; int two = 12; %> <%! public int operation(int i,int j){ return i > j ? i : j; } file://삼항 연산자를 사용하여 두개의 매개변수 값 중에 더 큰 값을 반환 시키는 메소드 입니다. %> 지금은 오전일까요 오후일까요? <%=(hour < 12)? 오전:오후\%>
one 와 two 둘 중에 큰 숫자는? <%=operation(one,two)%> file://operation(one,two)은 12가 리턴
:::97.IfEexample.html ::::::::::::::::::::::::::::::::::::::::::::::
If-else Example
file://form테그->>submit->>IfExample.jsp
:::100.IfExample.jsp ::::::::::::::::::::::::::::::::::::::::::::::
If-else Example <%! String msg; %> <% String name = request.getParameter(
ame); String color = request.getParameter(color); file://***** if (color.equals(lue)) { msg = 파란색; } else if (color.equals(
ed)) { msg = 붉은색; }else if (color.equals(orange)){ msg = 오렌지색; }else{ color = white; msg = 기타색; } %> > file://color변수는 <%=name%>님이 좋아하는 색깔은 <%=msg%>입니다.
file://이름[ 예:홍길동-value ]name=name file://색상[ ]name=color
:::100.ForExample.jsp ::::::::::::::::::::::::::::::::::::::::::::::
For Example 1에서 10까지 합은 ?
<% int i,sum = 0; for(i=1;i<=10;i++){ if(i<10){ %> <%=(i + +)%> <% }else{ file://else: 10보다 크거나 같을때 file://for(i=1;i<=10;i++){~ file://:1+2+3+4+5+6+7+8+9+10= out.println(i + = ); } sum += i; file://sum은 누적을 시킴 } %> <%=sum%>
:::102.WhileExample.html ::::::::::::::::::::::::::::::::::::::::::::::
While Example
------------------------------------------------ file://WhileExample.jsp문서 file://...................순서.3
While Example <% String msg = request.getParameter(msg); int number = Integer.parseInt(request.getParameter(
umber)); int count = 0; while(number>count){ %> <%=msg%>
<% count++; } %>
:::::::::::::::::::::::::::::::::::::::::::::::::
jsp스터디 2004 11 23
해당소스보기: http://www.6VJ.com/jsp/jsp1123.txt
(해당소스를 에러. 오류없이 볼 수 있습니다.)
생각보다 원본소스를 올리니 에러가 많이 보이네요
자세히 보는 방법은 위주소를 클릭한다음
***오른쪽마우스-소스보기를 클릭하시면 자세한 소스를 볼수있습니다.
원본소스보기: http://www.6VJ.com/jsp/source/camp04/
(폴더의 해당소스를 넣어 보세요) CommentExample1.jsp.jsp DeclaratiopnExample1.jsp DeclaratiopnExample2.jsp ExpressionExample1.jsp ExpressionExample2.jsp ForExample.jsp IfExample.html IfExample.jsp ScriptExample1.jsp ScriptletExample1$jsp.java ScriptletExample1.jsp ScriptletExample2.jsp ScriptTest.jsp Test3.jsp Test5.jsp WhileExample.html WhileExample.jsp
|