Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why set a JSP page session = "false" directive?

Tags:

jsp

session

I was wondering when you would want to set the following page directive in a JSP:

<%@ page session="false" %>

I know that it prevents the creation of the session object, but when would you need to do that? Is it considered a best practice when a JSP does not need to access the implicit session?

NOTE: The reason why I ask, is because it was in this Spring MVC tutorial and I assume the springsource folks know their stuff - http://blog.springsource.com/2011/01/04/green-beans-getting-started-with-spring-mvc/

like image 789
Mike G Avatar asked Apr 01 '11 15:04

Mike G


People also ask

What is the purpose of session page directive in JSP?

The page directive is used to provide instructions to the container that pertain to the current JSP page. You may code the page directives anywhere in your JSP page.

Which page directive should be used in JSP?

Which page directive should be used in JSP to generate a PDF page? Explanation: <%page contentType=”application/pdf”> tag is used in JSP to generate PDF.

Which page directive attribute can appear multiple times in a JSP file?

You can use the page directive more than once in a JSP page (translation unit). However, (except for the import attribute), you can specify a value for each attribute only once. The import attribute is similar to the import directive in a Java program, and accordingly you can use it more than once.

How do you declare in a JSP page that indicates whether or not the page is intended to be an error page of some other JSP page?

10)isErrorPage The isErrorPage attribute is used to declare that the current page is the error page.


1 Answers

One reason would be performance and memory. If you have a page that doesn't need to be involved in a session (like say, an about.jsp or faq.jsp) then the default behaviour of involving every JSP in a session will impose the overhead of creating a new session object (if one doesn't already exist) and increased memory usage as more objects reside on the heap.

This effect will be greatly exaggerated in case of a single page seeing high traffic from many unique users combined with a high bounce rate i.e. they users do not continue to browse but leave the site immediately after viewing that one page- the container will create a new session object per user which will never be used again and will ultimately be garbage collected after it times out - added over head of object creation, memory usage and garbage collection without giving you any real value.

like image 121
no.good.at.coding Avatar answered Oct 12 '22 02:10

no.good.at.coding