< Prev
Next >

JSP session Attribute

In JSP, session attribute of page directive specifies if the current JSP page takes part in the current HTTP session or not. Attribute session may either take the boolean value true or false.

Syntax of session attribute

<%@ page session = "true|false" %>

When session attribute is set to false, the current page does not participates in the current existing HTTP session and accessing the session object of HTTPSession class gives an error. Let's see how.
<%@ page session= "false" %>


<title>JSP session attribute</title>


<%@page import="java.util.*" session ="false" %>

<h2>Accessing a disabled session</h2>   <br/>

Session ID : <%= session.getId() %>   <br/>

Session creation time : <%= new Date(session.getCreationTime()) %>



executing Session2.jsp gives us an JSP error because we are trying to gather the information of the current session using the built-in session object of HTTPSession class(whose value is not set) because the current JSP hasn't participated in any session, as its session attribute was set to false.

Please share this article -

< Prev
Next >
< JSP isThreadSafe Attribute
JSP info Attribute >


Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition