The following example illustrates using <jsp:declaration> tag. This is an alternative to the <%! %> (declaration).
This tag is used to declare global variables or write member methods of the jasper-generated servlet class.
Note: You can write multiple <jsp:declaration>, <jsp:scriptlet> tags.
Previous: <jsp:scriptlet> tag
Next: <jsp:include> tag
This tag is used to declare global variables or write member methods of the jasper-generated servlet class.
index.jsp
<jsp:declaration>
int x=10;
String st;
public void print()
{
st="hello";
}
</jsp:declaration>
<jsp:scriptlet>
out.println(x);
// initialize st
print();
out.println(st);
</jsp:scriptlet>
Note: You can write multiple <jsp:declaration>, <jsp:scriptlet> tags.
Previous: <jsp:scriptlet> tag
Next: <jsp:include> tag