Syntax for a JSP Declarative is:
<%!
//your java code here
%>
JSP Declarative begins with the sign “<%!” and ends with this “%>” . Variables and functions defined in the declarative tag are class-level i.e they define functions and variable at the global level and they can be used anywhere in the JSP page. The code in the declaration tag is not available inside the service method (_jspService()) of JSP.
<%!
public String add(int a, int b)
{
int c=a+b;
return c+””;
}
%>
<%
int firstNum=2;
int secondNum=5;
%>
<html>
<head>
<title>Declaration in JSP</title>
</head>
<body>
This sum is : <%=add(firstNum,secondNum)%>
</body>
</html>