❮ Previous Next ❯

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>

❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved