• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to clear a request attribute/entry

 
Clarence Dyho
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply, Rovas.

Is there any workaround or any pattern to solve this problem?
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic