JSP Session Attribute

This attribute checks whether the JSP page is in a particular HTTP session or not. It can have true or false values. The default value is true.

Syntax:

<%@ page session="value"%>

Example:

welcome.jsp

<%@ page session="true" %> 
 
<html>
    <head>
        <title>session page directive example</title>
    </head>
    <body> 
        <h3>Hello this is a session page directive example.</h3> 
        <%
            out.print("Session id:" + session.getId());
        %>
    </body>
</html>

 

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>welcome.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>