---ÇнÀ°úÁ¤------------------ jsp±âº»¹®¹ý(1) -½ºÅ©¸³Æ®¿ä¼Ò -¼±¾ð¹® º¯¼ö¼±¾ð -½ºÅ©¸³Æ®¸´ -½ºÅ©¸³Æ®¸´ÀÇ È°¿ë -Ç¥Çö½ÄÀÇ È°¿ë -ÁÖ¼® -jspÀÇ ±âº» Á¦¾î¹® if-else(Á¶°Ç ºÐ±â¹®) for(¹Ýº¹¹®) while(¹Ýº¹¹®) ------------------------------ :::82.ScriptExample1.jsp :::::::::::::::::::::::::::::::::::::::::::::: JSP½ºÅ©¸³Æ® Example

Script Example1

<%! String declaration = "Declaration"; %> //<%! ~ %>: ¼±¾ðºÎÀÔ´Ï´Ù <%! public String decMethod(){ //¸Þ¼Òµå»ý¼º return declaration; //declaratinÀº °ªÀ» ¸®ÅÏ } %> //04:~ 12: ¹­¾î¼­ »ç¿ë°¡´É <% String scriptlet = "Scriptlet"; String comment = "Comment"; out.println("³»À尴ü¸¦ ÀÌ¿ëÇÑ Ãâ·Â : " + declaration + "

"); //À¥ºê¶ó¿ìÀú¿¡¼­ Ãâ·Â %> //¼±¾ðºÎ°¡ ¾Æ´Ï¶ó jsp¿µ¿ªÀ¸·Î ¼±¾ð¹®ÀÇ Ãâ·Â1 : <%=declaration%>

¼±¾ð¹®ÀÇ Ãâ·Â2 : <%=decMethod()%>

//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!!!"; %> //¸â¹öº¯¼ö´Â ¾Æ¹«°÷À̳ª ¼±¾ðÇصµ µÊ <%! String team = "Korea"; %> //¼±¾ðºÎ Ãâ·ÂµÇ´Â °á°ú´Â ? <%=name%> :::87.Declaration Example2.jsp ::::::::::::::::::::::::::::::::::::::::::::::

Declaration Example2

//¸â¹öº¯¼ö´Â ÃʱâÈ­ÇÏÁö ¾Ê¾Òµµ ÀÚµ¿ÃʱâÈ­µÈ´Ù. <%! int one; int two = 1; public int plusMethod(){ return one + two; } String msg; int three; %> one ¿Í twoÀÇ ÇÕÀº ? <%=plusMethod()%>

//È£Ã⸮ÅÏ String msgÀÇ °ªÀº ? <%=msg%>

//ÃʱâÈ­ null int threeÀÇ °ªÀº ? <%=three%> //threeÀº `0`À¸·Î ÃʱâÈ­ :::90.Scriptlet Example2.jsp ::::::::::::::::::::::::::::::::::::::::::::::

Scriptlet Example2

<% float f = 2.3f; //2.3f ->±âº»Çü-¹Ý¿Ã¸² //Âü°í //float f´Â º¯¼ö = 2.3fÀº »ó¼ö; //½Ç¼ö´Â ÀÚµ¿À¸·Î doobleÇü int i = Math.round(f); java.util.Date date = new java.util.Date(); %> ½Ç¼ö fÀÇ ¹Ý¿Ã¸²°ªÀº? <%=i%>

ÇöÀçÀÇ ³¯Â¥¿Í ½Ã°£Àº? <%=date.toString()%> //toString :¹®ÀÚÇüº¯È­ [Note] <%@ page ~ %> <%@ :Áö½ÃºÎ <%! :¼±¾ðºÎ <%= :Ç¥Çö, Ãâ·Â <%-=%> <%-- --%> <%@ page impoet="Java.util*,Java.awt* %> :::92.Expression Example1.jsp ::::::::::::::::::::::::::::::::::::::::::::::

Expression Example1

<%! String name[] = {"Sun","Java","JSPStudy"}; //¼¼°³ÀÇ ¹è¿­¼º°ø //*nameÀ̶ó´Â ¹è¿ªº¯¼ö¸¦ ¼±¾ð°ú µ¿½Ã¿¡ °ªÀ» ºÎ¿© ÇÏ¿´½À´Ï´Ù. %> <% for (int i=0;i //*Á¤¼ö i°¡ ¹è¿­ÀÇ ±æÀ̸¸Å­ for¹®À» ·çÇÁ·Î µ¹·Á¼­ Ãâ·ÂÇÕ´Ï´Ù. <%}%>
<%=i%> <%=name[i]%>
//À§»ó´Ü¼Ò½º Áß¿äµµ***** //°Ô½ÃÆÇ...¸¹À̾²ÀÓ :::92.Expression Example2.jsp ::::::::::::::::::::::::::::::::::::::::::::::

Expression Example2

<% java.util.Date date = new java.util.Date(); int hour = date.getHours(); //getHoursÀº ½Ã°£¸¸ ´ã°í //À½¿µ : Date Ŭ·¡½º¿¡¼­ getHours() ¸Þ¼Òµå¸¦ »ç¿ëÇÏ¿© ½Ã°£(hour) °ª¸¸ ¹ÝȯÀ» ÇÕ´Ï´Ù. int one = 10; int two = 12; %> <%! public int operation(int i,int j){ return i > j ? i : j; } //»ïÇ× ¿¬»êÀÚ¸¦ »ç¿ëÇÏ¿© µÎ°³ÀÇ ¸Å°³º¯¼ö °ª Áß¿¡ ´õ Å« °ªÀ» ¹Ýȯ ½ÃÅ°´Â ¸Þ¼Òµå ÀÔ´Ï´Ù. %> Áö±ÝÀº ¿ÀÀüÀϱî¿ä ¿ÀÈÄÀϱî¿ä? <%=(hour < 12)? "¿ÀÀü":"¿ÀÈÄ"%>

one ¿Í two µÑ Áß¿¡ Å« ¼ýÀÚ´Â? <%=operation(one,two)%> //operation(one,two)Àº 12°¡ ¸®ÅÏ :::97.IfEexample.html ::::::::::::::::::::::::::::::::::::::::::::::

If-else Example

//°ªÀ»³Ñ±â´Â ¹æ½Ä:post´Â ¿¬°áÁÖ¼ö²¿¸®¸¦ ¼û±â°í // get¹æ½ÄÀº ¿¬°á°í¸®¸¦ º¸¿©ÁÖ°í ÀÖ´Ù. À̸§ :

//ÀÔ·ÂÇÏ´Â À̸§ ÁÁ¾ÆÇÏ´Â »ö±ò :

//formÅ×±×->>submit->>IfExample.jsp :::100.IfExample.jsp ::::::::::::::::::::::::::::::::::::::::::::::

If-else Example

<%! String msg; %> <% String name = request.getParameter("name"); String color = request.getParameter("color"); //***** if (color.equals("blue")) { msg = "ÆĶõ»ö"; } else if (color.equals("red")) { msg = "ºÓÀº»ö"; }else if (color.equals("orange")){ msg = "¿À·»Áö»ö"; }else{ color = "white"; msg = "±âŸ»ö"; } %> > //colorº¯¼ö´Â <%=name%>´ÔÀÌ ÁÁ¾ÆÇÏ´Â »ö±òÀº <%=msg%>ÀÔ´Ï´Ù. //À̸§[ ¿¹:È«±æµ¿-value ]name=name //»ö»ó[ ]name=color :::100.ForExample.jsp ::::::::::::::::::::::::::::::::::::::::::::::

For Example

1¿¡¼­ 10±îÁö ÇÕÀº ?

<% int i,sum = 0; for(i=1;i<=10;i++){ if(i<10){ %> <%=(i + " +")%> <% }else{ //else: 10º¸´Ù Å©°Å³ª °°À»¶§ //for(i=1;i<=10;i++){~ //:1+2+3+4+5+6+7+8+9+10= out.println(i + " = "); } sum += i; //sumÀº ´©ÀûÀ» ½ÃÅ´ } %> <%=sum%> :::102.WhileExample.html ::::::::::::::::::::::::::::::::::::::::::::::

While Example

//..................¼ø¼­.2 ¹Ýº¹ÇÏ°í ½ÍÀº ¹®±¸ :

¹Ýº¹ÇÏ°í ½ÍÀº Ƚ¼ö :

//...................¼ø¼­.1

------------------------------------------------ //WhileExample.jsp¹®¼­ //...................¼ø¼­.3

While Example

<% String msg = request.getParameter("msg"); int number = Integer.parseInt(request.getParameter("number")); 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