• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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