you need to use an http session attribute, which under the covers
is stored in a somewhere in applciation server, and indexed by a key
provided in a cookie or a mangked URL. Look at Core Servlets and Java Server
Pages, by Marty Hall, chapters 8 and 9.

Cheers, Andy

CHAPTER 8
Handling Cookies 178

8.1 Benefits of Cookies 179
Identifying a User During an E-commerce Session 180
Avoiding Username and Password 180
Customizing a Site 180
Focusing Advertising 181
8.2 Some Problems with Cookies 181
8.3 The Servlet Cookie API 183
Creating Cookies 183
Cookie Attributes 183
Placing Cookies in the Response Headers 186
Reading Cookies from the Client 186
8.4 Examples of Setting and Reading Cookies 186
8.5 Basic Cookie Utilities 190
Finding Cookies with Specified Names 190
Creating Long-Lived Cookies 191
8.6 A Customized Search Engine Interface 191
CHAPTER 9
Session Tracking 198

9.1 The Need for Session Tracking 199
Cookies 200
URL-Rewriting 200
Hidden Form Fields 201
Session Tracking in Servlets 201
9.2 The Session Tracking API 201
Looking Up the HttpSession Object Associated with the Current Request 202
Looking Up Information Associated with a Session 202
Associating Information with a Session 205
Terminating Sessions 206
Encoding URLs Sent to the Client 206
9.3 A Servlet Showing Per-Client Access Counts 207
9.4 An On-Line Store Using a Shopping Cart and Session Tracking 209
Building the Front End 210
Handling the Orders 215
Behind the Scenes: Implementing the Shopping Cart and
Catalog Items 220


-----Original Message-----
From: hua ge
To: [EMAIL PROTECTED]
Sent: 11/2/00 2:45 PM
Subject: help:session variable could not retain old data if back button
clicked

Hi,

can someone give me some help, I stucked here almost 2 days...

this is what I did:

1. searchForm.jsp will submit to a servlet

2. the servlet store the search results as an object  by coding:
        request.setAttribute(object name, value);

3.  then the servlet will forward to a jsp page to display the data
there.


        RequestDispatcher rd =
getServletContext().getRequestDispatcher("/employers/ge/results.jsp?mode
=groupSearch");
        rd.forward(request,response);


4. results.jsp will retrive data out by coding:
       request.getAttribute(object name, value);


5. results.jsp will loop through and display all records
   lines, each line contains couple key attributes such
   as name, address, phone... the name field will be a
   hyperlink to details.jsp page to show all the   attributes of this
records.

6.  results.jsp will store the retrived object in a session variable so
when
the name field link bring to the detail page,the same object can be
retrive
out there.


7. the results.jsp will dynamic showing [previous] [next]
   link if the total record count of the results more  than 10.

8. on the bottom of results.jsp will has a hyperlink "begin a new
search"
bring user back to the
searchForm.jsp.


the above steps are all works fine if I do one search after another.


PROBLEMS:

1. if I click the browser back button to
previous result page, it looks like the previous results still showing
there, but since the session variable already overwriten by the lastest
search results, so the details page will has wrong data.

2. if I go back through browser to previous results page and that page
has
[previous] [next] link, if I click either [previous] or [next] link,
then
the results will mess up, it will based on the latest results count to
recalculate the page number instead of the previous results count.


can some one point out how I can retain the old data stroed in session
variable if the browser back button clicked??

appreciate your help.

Helen

________________________________________________________________________
_
Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.

Share information about yourself, create your own public profile at
http://profiles.msn.com.

========================================================================
===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to