×
☰ See All Chapters

Declaration tag in JSP

  • Declarations tags are used to declare/write class members i.e. instance/static variables and methods. 

  • All the declarations of the JSP will be placed directly inside the servlet class and outside the jspService() method. 

  • Syntax of JSP declarations tag is 

   <%!

Java methods and variables declaration

   %>

 

JSP Declaration Tag Example

Project directory structure

jsp-declaration-0
 

declarationsDemo.jsp

<%!

        String sayHello(String name) {

                return "Hello "+ name;

        }

%>

<%@ page import="java.util.Calendar"%>

<%@ page session="false"%>

<%

        out.println(sayHello("Manu Manjunatha"));

%>

Output

jsp-declaration-1
 

 


All Chapters
Author