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

Facebook Google Pinterest Reddit Tumblr Twitter



< Prev
Next >
< JSP isThreadSafe Attribute
JSP info Attribute >
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2