---ÇнÀ°úÁ¤------------------
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
|