A session is an object associated with a visitor. Data can be put in the session and retrieved from it, much like a Hash table. A different set of data is kept for each visitor to the site.
Here is a set of pages that put a user's name in the session, and display it elsewhere. Try out installing and using these.
First write a form, let us call it DemoSession.html
<HTML> <BODY> <FORM METHOD=POST ACTION="DemoSession.jsp"> What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20> <P><INPUT TYPE=SUBMIT> </FORM> </BODY> </HTML>
The target of the form is "DemoSession.jsp", which saves the user's name in the session.
<% String name = request.getParameter( "username" ); session.setAttribute( "theName", name ); %> <HTML> <BODY> <A HREF="NextPage.jsp">Continue</A> </BODY> </HTML>
The DemoSession.jsp saves the user's name in the session, and puts a link to another page, NextPage.jsp.
NextPage.jsp shows how to retrieve the saved name.
<HTML> <BODY> Hello, <%= session.getAttribute( "theName" ) %> </BODY> </HTML>
The session is kept around until a timeout period. Then it is assumed that the user is no longer visiting the site, and the session is discarded.