Declaration Tag

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.
Note : In declaration block we can not write anything to the output stream.
Syntax of Declaration tag
<%! java class variable and method declarations % >
<html> <head> <title>Welcome to Declaration tag example </title> </head> <body> <%! 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> </body> </html>
Download this example


Latest Tutorial

Most Visited Tutorial