Explain why and how to disable session in a JSP page.

Explain why and how to disable session in a JSP page.

Answer
Disabling the session improves the performance of a JSP container. When a JSP is requested, an HttpSession object is created to maintain a state that is unique for each client. The session data is accessible as an implicit session object and sessions are enabled by default.

Session object uses the server resources which causes an increase in the traffic as the session ID is sent from server to client and then vice versa. If a few JSP pages get a large number of hits, there is no need to identify the user. Hence, in this case it is better to have a session in a JSP page disabled.

The session in the JSP file can be disabled by setting the session attribute to false in the following manner:

 <%@ page session="false" %>

Explain why and how to disable session in a JSP page.

The JSP container performance is improved by disabling the session in some of the JSPs.

The server resource is utilized by session objects. A small amount of system resources is used by each session object as it is reside on the server. This causes increase in the traffic as the session ids are sent to the client. In a situation where thousands of users are hitting the browser and there is no need to identify each and every user, it is always better to disable session in the corresponding JSP pages.

A session can be disabled by setting the session attribute to false. The following is the example to disable the session object using page directive:

 <%@ page session="false" %>
Benefits of JSP
JSP benefits - JSP technology emphasizes on reusing the components that helps to develop more purposeful....
JSP Scriptlet - What is Scriptlet tag?
JSP Scriptlet - Scriptlet tag is a type tag used for inserting Java Code into JSP and is written as...
Explain how JSP handle run-time exceptions
JSP exceptions - The errorPage attribute of the page directive can be used to redirects the browser to an error processing page, when uncaught exception...
Post your comment