Siddharth Mehta
Siddharth Mehta

Reputation: 465

Removing success message after jsp page refresh?

I have a JSP page which displays a success message on successful deletion of an item.

However, if the page is refreshed, I want the message to not be displayed. I tried all I could do but it just doesn't happen.

I am setting the attribute in a Struts 2 class in request scope. I am retrieving the same attribute in my JSP page using request.getattribute(). After the if statement, I am trying to set the same attribute to null. But the success message remains after refreshing the page which I don't want.

Please help!

Upvotes: 1

Views: 1846

Answers (1)

iullianr
iullianr

Reputation: 1284

If you refresh the page, (from the browser I assume) you are actually sending the same request to server again. Which means, it will execute whatever it executes, put again that attribute on request, and you will get it back in the JSP page. If you want to avoid that, you should have a way to tell, on the server side, that the operation has been already executed in order not to put the attribute on the request( for example, if you insert something, always check before if is not inserted already, and if so, just don't put that attribute on the request).

Upvotes: 2

Related Questions