Thursday, February 17, 2011

JSP Declaratives



Syntax for a JSP Declarative is:
<%!
//your java code here
%>
JSP Declarative begins with the sign “<%!” and ends with this “%>” . Variables and functions defined in the declarative tag are class-level i.e they define functions and variable at the global level and they can be used anywhere in the JSP page. The code in the declaration tag is not available inside the service method (_jspService()) of JSP.
<%!
         public String add(int a, int b)
         {   
             int c=a+b;

            return c+””;
         }

%>

<%
 int firstNum=2;
 int secondNum=5;
%>
<html>
<head>
<title>Declaration in JSP</title>
</head>

<body>
This sum is : <%=add(firstNum,secondNum)%>
</body>
</html>

No comments:

Post a Comment

Please comment, if you like the post, you find any mistake or if you have any query.