A declaration is a block of java code in JSP that is used to declare class variables and method in the generated servlet. Declaration are initilized when JSP page is initilized, and create an instance in the generated servlet, so that anything defined in a declaration block is available to whole page.
: In declaration block we can not write anything to the output stream.
Syntax of Declaration tag
<%! java class variable and method declarations % >
<title>Welcome to Declaration tag example </title>
<%! int counter= 10;
public String login(String name)
return "Welcome " + name ;
<p> The Value of Counter <%= counter %> </p>
<p> Hello you are most <%= login("Sunil") %> </p>
Download this example