Advertisement



< 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" %>


Session2.jsp
<html>

<head>
<title>JSP session attribute</title>
</head>


<body>

<%@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()) %>

</body>

</html>



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 >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement