Scripting Elements´Â JSP Page¿¡ Á÷Á¢ Äڵ带 ³¢¿ö ³ÖÀ» ¼ö ÀÖ°Ô ÇÕ´Ï´Ù. JSP Scripting Elements´Â ¼¼°¡Áö ŸÀÔ( Declaration, Expression, Scriptlet  ) ·Î ³ª´­ ¼ö ÀÖ½À´Ï´Ù.

 

 

1. Declaration

º¯¼ö¿Í ¸Þ¼Òµå¸¦ Á¤ÀÇÇÒ ¶§ »ç¿ëÇÏ´Â ÅÂÅ©ÀÔ´Ï´Ù.

Syntax

<%! declaration %>

 

2. Expression

ÆäÀÌÁö Ãâ·ÂÀ» À§ÇÑ ¹®¹ýÀÔ´Ï´Ù.

Syntax

<%= expression %>    

 

Example

ex4.jsp

<%@ page contentType="text/html;charset=euc-kr" %>

<%!

       /*

       ÀÌŸ± ±ÛÀڷΠǥÇöµÈ ºÎºÐÀÌ º¯¼ö¿Í ¸Þ¼Òµå¸¦ ¼±¾ðÇÑ Declaration

     ºÎºÐÀÔ´Ï´Ù.

       */

       int[] mathPoint = { 30,50,60,20 };

 

       public double getAverage(){

                    double sum = 0;

                    for(int i=0;i<mathPoint.length;i++) sum += mathPoint[i];

                    return sum/mathPoint.length;

       }

 

       public double getBunsan(){

                    double sum = 0;

                    double average = getAverage();

 

                    for(int i=0;i<mathPoint.length;i++){

                                 sum += Math.pow((mathPoint[i]-average),2);

                    }

                    return sum/mathPoint.length;

       }

 

       public double getPyosun(){

                    return Math.sqrt(getBunsan());

       }

%>

<html>

<body>

Declaration & Expression<p>

 

ÇØ´ç Á¡¼ö¿¡ ´ëÇÑ °á°ú

Æò±Õ : <%= getAverage() %><br>  // Expression

ºÐ»ê: <%= getBunsan() %><br>

Ç¥ÁØÆíÂ÷ : <%= getPyosun() %><br>

 

 

3. Scriptlet

Declaration & ExpressionÀº »ç¿ëÀÌ Á¦ÇÑÀûÀÌÁö¿ä. ±×·¯³ª ScriptletÀº ¾ÆÁÖ ÀÚÀ¯½º·´°Ô ÀÚ¹ÙÄڵ带 »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. PHPÀÇ <? php code ?>, ASPÀÇ <% asp code %> ¿Í µ¿ÀÏÇÕ´Ï´Ù.

½ÇÁ¦·Î´Â ScriptletÀÌ ¸¹ÀÌ »ç¿ëµÇ¸é µÉ¼ö·Ï Presentation Layer¿Í Business Layer ºÐ¸®ÀÇ ¹®Á¦·Î ÁÁÁö ¾Ê´Ù°í ÇÕ´Ï´Ù. µÉ ¼ö ÀÖ´Â ÇÑ »ç¿ëÀ» Áö¾çÇÏ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.

 

Syntax

<% expression %>    

 

Example

<%@ page contentType="text/html;charset=euc-kr" %>

<%

       int intYear =0;

       String strYear = request.getParameter("YEAR");

      

       if(strYear != null){

                    intYear = Integer.parseInt(strYear);

       } else {

                    intYear = -1;

                    strYear = "";

       }

      

%>

<html>

<body>

Scriptlet<p>

<form action="ex6.jsp">

Input your year : <input type=text name=YEAR value="<%=strYear%>">

<input type=submit value="È®ÀÎ">

<p>

</form>

<p>

<%

/*  Ưº°ÇÑ °ÍÀÌ ¾øÁö¿ä.. ¾ÆÁÖ¾ÆÁÖ °£´ÜÇÏÁö¿ä¡¦   */

       if(intYear >= 19){ %>

                    <font color=blue>»ó¸ðÀÇ ¾ÆÁÖ ¾ßÇÑ »çÁø</font>

<%

       } else if(intYear > 0 && intYear < 18) { %>

                    <font color=red>¾ÆÁ÷Àº ¶§°¡ ¾Æ´Ñ°Í °°±º¿ä. ¤»¤»¤»¤»¤»</font>

<%

       }

%>

 

°­ÁÂÀÇ reference

- Web Development with Java Server Pages. by Duane K. Fields & Mark A. Kolb ,°û¿ëÀçÆí¿ª ; InfoBook, Manning

-  http://java.sun.com/products/jsp/tags/tags.html

-  http://myhome.shinbiro.com/~jimmy/home.htm