File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Problem in displaying value from session object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in displaying value from session object" Watch "Problem in displaying value from session object" New topic

Problem in displaying value from session object

Yogendra Butola

Joined: Jun 13, 2006
Posts: 1
I working on attachment functionality on JSP page
Here are the steps I follow

1) On the jsp page I selects the file clicks the "Attach" link.
2) The request goes to a servlet which uploads the file to a directory.
3) The servlet shows the messgae "Your file has been uploaded", and a close button below that.
In the servlet I've set the filename in the session object.

4) When I click the "CLOSE" button, the servlet takes me back to the JSP page.
On the "CLOSE" button, I'm using "history.go(-1)", which will take me to the previous page

5) On the JSP page I'm displaying the name of the file, by retrieving from the HttpSession object.

However the file name dosen't get displayed.

When I click the browser's refresh button, the file name gets displayed

Please let me know why the JSP is not able to retrive the value from the session object.

Is it because I haven't submitted a new request.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

It sounds like you're seeing a cached version of the previous page when you click the back button.

Search this forum (and Google) with keywords 'pragma' and 'cache' for tips on preventing your browser from caching pages (browsers are not all compatible in this regard so you may need to suggest it in more than one way to achieve consistent results).

A better approach would be to use the post-redirect-get pattern to eliminate the need to duplicate the back button with Javascript.
After your upload, use response.sendRedirect to redirect the browser to your page. This will force a new request on the client side.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Problem in displaying value from session object
It's not a secret anymore!