keith
Posts: 1
Nickname: keithjava
Registered: Sep, 2002
|
|
Re: How to do session tracking in JSP
|
Posted: Sep 16, 2002 8:36 PM
|
|
First we have a form, let us call it GetName.html
<HTML> <BODY> <FORM METHOD=POST ACTION="SaveName.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 "SaveName.jsp", which saves the user's name in the session. Note the variable "session". This is another variable that is normally made available in JSPs, just like out and request variables. (In the @page directive, you can indicate that you do not need sessions, in which case the "session" variable will not be made available.) <% String name = request.getParameter( "username" ); session.setAttribute( "theName", name ); %> <HTML> <BODY> <A HREF="NextPage.jsp">Continue</A> </BODY> </HTML> The SaveName.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>
|
|