8

I have a project based in Spring Web model-view-controller (MVC) framework. The version of the Spring Web model-view-controller (MVC) framework is 3.2.8 deployed on a WebLogic Server Version: 12.1.2.0.0

I have this form in 1 JSP

  <form:form commandName="deviceForm" 
                                                name="deviceForm"
                                                id="deviceFormId" 
                                                method="post"
                                                action="${contextPath}/device/${deviceForm.device.id}" 
                                                htmlEscape="yes"
                                                enctype="multipart/form-data">

I make a couple of actions using the method POST.. after this I use the browser (IE11) back button and I got this error

Webpage has expired




Most likely cause:
•The local copy of this webpage is out of date, and the website requires that you download it again.


Something to try:



  Click on the Refresh button on the toolbar to reload the page. After refreshing, you might need to navigate to the specific webpage again, or re-enter information.  



More information  More information   


If you continue to have this problem, try the following: 
1.In Internet Explorer, click the Tools button , click Internet Options, and then click the Advanced tab.
2.Scroll down and clear the “Do not save encrypted pages to disk” option in the Security settings.

I also tried to redirect in the POST method

  response.setStatus(HttpServletResponse.SC_SEE_OTHER   );
        response.setHeader("Location", /device/" + device.id");
        response.setHeader("Connection", "close");
        response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
        response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
        response.setHeader("Expires", "0"); // Proxies.
return "redirect:/device/" + device.id"; 
Amadeu Cabanilles
  • 913
  • 3
  • 19
  • 47

5 Answers5

3

Just set the method form method to get, and when you click on the submit button, just change it to post

en Lopes
  • 1,863
  • 11
  • 48
  • 90
0

If you make any POST request browser will always show you "Webpage has Expire". If you refresh the page POST request again submit with all parameters , so Use POST Request only when you have a form to submit or something you can not send in url.

1) Convert all normal request to GET Request and keep only submit request as a POST Request.

rajat
  • 1
  • 1
0

Add this tag to your html page:

<meta http-equiv="Cache-control" content="public">

More info here: https://support.microsoft.com/en-us/help/183763/error-message-warning-page-has-expired-the-page-you-requested...

artemisian
  • 2,976
  • 1
  • 22
  • 23
0

The problem you deal with is that navigation from browser follows general rules which are independent from your webapp logic.

There is no general way to solve this problem, but you can use javascript to change the navigation history so that it matches your logic.

You can in fact replace the top element of your history so that there is no post in your history.

This answer has a good example to do this.

Community
  • 1
  • 1
minus
  • 2,646
  • 15
  • 18
0

Actually this is a caching related issue. You can solve by the following way.

Suggestion#1

BalusC has given a solution by using a filter. No need to add all jsp files. It will less your pain.

To disable browser cache for JSP pages, create a Filter which is mapped on an url-pattern of *.jsp and does basically the following in the doFilter() method:

HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0
httpResponse.setDateHeader("Expires", 0); // Proxies.

This way you don't need to copypaste this over all JSP pages and clutter them with scriptlets.

To enable browser cache for static components like CSS and JS, put them all in a common folder like /static or /resources and create a Filter which is mapped on an url-pattern of /static/* or /resources/* and does basically the following in the doFilter() method:

httpResponse.setDateHeader("Expires", System.currentTimeMillis() + 604800000L);

Resource Link: https://stackoverflow.com/a/3055297

Suggestion#2

In your jsp file, you can add. It will solve your issue.

<%
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
%>

Resource Link:

Add an Expires or a Cache-Control header in JSP

Suggestion#3

Microsoft support page has given browser related solution like below

  1. You can refresh the page for resubmitting.
  2. To resolve this problem, either disable the "Do not save encrypted pages to disk" option, or obtain and install the latest version of Internet Explorer.

Resource Link: Solution for Error Message: Warning: Page Has Expired: The Page You Requested

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132