Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
is an instance of javax.servlet.http.HttpSession, created by default.
You can use it to track a user's actions through different pages by using
You can create and associate any object with the session, not just Strings. Vector, HashMap or some other Collection, for instance.
The attributes will only remain valid FOR the DURATION OF the SESSION !!!!
The session object stays alive for a certain amount of time without user activity.
This can be configured in the J2EE Server ( Servlet/JSP container ) and is vendor-specific. Default value often 30 minutes.
There's a corresponding set- method that applies only to the current session :
session.setMaxInactiveInterval( 600 ) ;
= 10 minutes.
You can even terminate a session yourself by issuing :
session.invalidate( ) ;
Notice the syntax :
Notice the curly brackets !
In EL, session properties can be accessed via pageContext.
Attributes through sessionScope.
Or even this way,...
if there's no 'Order1' attribute in the first two of these scopes, because these are searched in the order given for attributes that are not qualified.
If you want to attach an object so that can be found in other sessions, too, you can use
Other EL objects that haven't been mentioned sofar.
Where a session is not needed, you can boost performance somewhat by adding this to the start of such a page.
In the JSTL lesson you can see how this sort of thing is done using the JSTL 'set' tag.
The JspWriter referred to by 'out' is present by default, so you can output (HTML)text straight from Java, using print or println.