JSP disable or prevent session creation - Java @ Desk

Wednesday, May 7, 2014

JSP disable or prevent session creation

JSP disable or prevent session creation

Yes. We can disable session creation for a JSP.

Session creation is a heavy process. When a user visits an application for the first time, the container automatically associates a session to that user. But in some cases, session object is not at all required. Following are the examples :

1) Login Page
2) Help Page
3) Logout Page
4) Pages with frames. In this case, all the frames will create their own session which would be very heavy operation.

and much more. In such cases, a JSP page should declare a page directive "<%@ page session="false" %>". In this case, a user session will not be created.

Example :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>






No comments:

Post a Comment