[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

How can I refresh my jsp by clicking "return" button?

Supposed I have two jsps called jsp1.jsp and jsp2.jsp. If I click hte submit in jsp1 it will goto jsp2. If I click the "return" in browser it should go back to jsp1. But what I want is: as it goes back to jsp1 it should refresh it again just like cilcking the refresh button in browser.

How can I do that? Using a js-function?
0
chenwei
Asked:
chenwei
  • 2
  • 2
1 Solution
 
TimYatesCommented:
Stick this in the top of jsp1:

<%
        // Set to expire far in the past.
        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
%>
0
 
TimYatesCommented:
And by the "return", I guess you mean the back button?

Tim
0
 
chenweiAuthor Commented:
1.
Yes, what my "return" means "back". :-)

2.
I put all the codes above at the beginning of my jsps. But it seams it works different as by clicking the "refresh" button. Exactly to say, I have a content.jsp and a logoff.jsp. If I click the link "logoff" in content.jsp it will go to the logoff.jsp.

At the beginning of my content.jsp:
...
<%
        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        response.setHeader("Pragma", "no-cache");
%>
<%
 if( session.getAttribute( "User" ) != null ){
   response.sendRedirect("./index.jsp");
 }
%>

And at the beginning of my logoff.jsp:
...
<%
        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        response.setHeader("Pragma", "no-cache");
%>
<%
         session.removeAttribute("User");
         session.invalidate();
%>
...

What I want is: After I've logoff and if I click "back", it will go to the index.jsp. But it doesn't now. I have to click the "refresh".

3.
What's the difference between
response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
and
response.setHeader("Expires", 0);
?
0
 
chenweiAuthor Commented:
Is there any way to catch the action of "back" in jsp?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now