JSP Declaration Tag

JSP declaration tag is used to declare fields and methods. The code written inside the jsp declaration tag is placed outside the service() method of auto generated servlet. So it doesn't get memory at each request.

The general form JSP declaration tag is:

<%! field or method declaration %>

  

JSP Scriptlet tag vs. JSP declaration tag

 

JSP Scriptlet Tag JSP Declaration Tag
declare variables not methods. declare variables as well as methods.
placed inside the _jspService() method. placed outside the _jspService() method.

Example:

index.jsp

<html>
<body>
<%! int x=100; %>
<%= "Value of x is:"+x %>
</body>
</html>

 

OUTPUT:

declare

Example:

index1.jsp

<html>
<body >
<%!
int area(int l, int b)
{
return (l*b);
}
<%= "area of rectangle is:"+area(3,4);%>
</body>
</html>

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment