File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to clear a request attribute/entry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to clear a request attribute/entry" Watch "How to clear a request attribute/entry" New topic
Author

How to clear a request attribute/entry

Clarence Dyho
Greenhorn

Joined: Sep 17, 2001
Posts: 23
Thank you again for your reply, Rovas.

I did something similar. Only I put them in my servlet instead of in my JSP :

response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", -1);

What happens is that the page expires when the back button is pressed. Not the most elegant solution but it should work for now. Thank you for your help.
Clarence Dyho
Greenhorn

Joined: Sep 17, 2001
Posts: 23
Hello

I have an entry form. When the user clicks on submit, the information is stored into the DB and the user is sent back to the same form with an alert message informing him that the DB insert was successful. I set a request attribute that the JSP checks to see if the DB insert is successful. If so, then the alert message is displayed and then I remove the attribute from the request.

Using tokens, I was able to display the same page without the alert message when the user refreshes the page.

My problem is when the I click the back button and then press the forward button again, the alert message is redisplayed. It's like when I hit the back button, the attribute that I have set subsequently removed still persist.

What work arounds can I do to clear the attribute permanently from the request and prevent the alert from firing when I go back or forward a page?

I am using Struts framework BTW but I feel this is more on the JSP side.

Thank you very much.
Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
I believe that when you press the forward button, your browser is just redisplaying the results - this is normally the case unless you're using https. If the above is true, then your web server is not involved and neither are request attributes.
Clarence Dyho
Greenhorn

Joined: Sep 17, 2001
Posts: 23
Thank you for your reply, Rovas.

Is there any workaround or any pattern to solve this problem?
Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
You can add the following to your html/jsp. This will tell the browser to re-send the request rather than redisplay the results. You will have to decide what do on the server side in that case.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to clear a request attribute/entry
 
Similar Threads
history.back() in Netscape 7.2
back button
Data stored without notice
My First Struts App
HttpServletRequest question