Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me with session tracking example

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two html pages and I have the submit button in second page.
I have to save the data of the first page when the user navigates to the
second one. This can be done using Session tracking.
What I know is u can start of saying
HttpSession ses = request.getSession(true);
I am not sure how I will save the value in the fields of the first form.
Should I create String variables to save the data. If that is the case
I need not create a session object. What I will do is I will place a button called "continue" in my first html and check. If it is equal to
"continue" I will save it in String variables and if it is "submit" then I will try to do the reqd manipulation.

I am really sought of breaking my head about how to use session object to
save my data in first page. can anyone help me with a example code.
Just give me an example using two fields in first page and two fields
along with submit button in second page.
Please... I need ur help.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple approach - assuming your servlet or JSP writes the second page, is to just re-write those first page form values into the second page form as type="hidden" variables, that way when you process the second page all variables will be there.
Your servlet can tell if it is getting a response from the first or second page with the same technique.
<input type="hidden" name="page" value="first" >
Sessions would also work but this is simpler and works no matter how the browser is set up.
WBB
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic