user3835327
user3835327

Reputation: 578

How to remove getParameter() value when page is refreshed

How to remove the parameter value when I refresh the page using F5/ reload? The expected result is when B.jsp sends the status back to A.jsp I want to make the value empty if the user hits refresh page.

A.jsp:

<%String VALUE = request.getParameter("STATUS");%>

B.jsp:

<%send.responseRedirect("A.jsp?STATUS="Y");%>

Upvotes: 4

Views: 3704

Answers (2)

MaVRoSCy
MaVRoSCy

Reputation: 17839

When an html page is posted to a servlet/jsp or any other kind of web resource it contains some headers. These headers among others contain the request's parameters. When the user hits refresh/f5 on his browser what the browser does is to re-post the same header as before. So, this issue is browser specific.

Now you can deal that in a number of ways. One way would be to store the current value in a session variable and then a request comes with the request paramater is the same as the session attribute value then you can treat it as a refresh action.

Consider the code below for newjsp.jsp:

String param = request.getParameter("param");
if (session.getAttribute("PARAM") == null) {
    out.print("This is a NEW request");
    session.setAttribute("PARAM", request.getParameter("param"));
} else if (session.getAttribute("PARAM").toString().equalsIgnoreCase(param)) {
    out.print("This is a REFRESH");
    session.removeAttribute("PARAM");
} else {
    out.print("This is a NEW request");
    session.setAttribute("PARAM", request.getParameter("param"));
}

Invoke it using 'newjsp.jsp?param=xyz123', and try hitting the refresh.

Upvotes: 2

cristianhh
cristianhh

Reputation: 138

if you do not use large images on your web page you could also remove caching with these lines

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

Upvotes: 1

Related Questions