Search code examples
internet-explorerjspfile-uploadback-buttonmultipartform-data

Page Expired issue on IE with multipart/form-data form


I have a "Page Expired" issue on IE if I specify the enctype="multipart/form-data" in the form tag.

By simplifying, I have 3 JSP pages page1.jsp, page2.jsp and page3.jsp.

page1.jsp (which contains a form with enctype="multipart/form-data") submits to page2.jsp and page2.jsp submits to page3.jsp.

If I:

  1. submit to page2.jsp
  2. submit again from page2.jsp to page3.jsp
  3. go back from page3.jsp to page2.jsp (using history.back() javascript), I get "Page Expired".

I read about cache-control, but setting these page with cache-control private or public doesn't change the situation

// page1.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<html>
<head>
</head>
<body>
   <form method="post" enctype="multipart/form-data" action="page2.jsp">
File to upload: <input type=file name=upfile>
<input type=submit value="Go to page2"> 
</form> 

 // page2.jsp
<html>
<head>  
</head>
<body>
   <form method="post" action="page3.jsp">            
   <input type=submit value="Go to page3"> 
   </form> 
 </body>
</html>


// page3.jsp
<html>
<head>
</head>
<body>
    <form method="post" action="end.jsp">
    <input type="button" value="Go to page 2" onclick="javascript:history.back();"> 
    <input type=submit value="Go to end">        
    </form>
</body>
</html> 

Solution

  • just use post-redirect-get paradigm:

    1. page1 -- post --> servlet1
    2. servlet1 -- process data then redirects --> page2
    3. page2 -- post --> servlet2
    4. servlet2 -- process data then redirects --> page3

    this way, browsers will not ask to re-submit or display "page expired" on back pressed

    however you can reduce the number of pages/servlets implementing this way:

    page2.jsp

    <% 
        if("POST".equals(request.getMethod()) 
        {
            // process submitted params/files
            response.sendRedirect(request.getRequestURI()); // redirect to the same page
        }
    %>
    <html>
        blah blah blah
    </html>
    

    or you can simply use ajax.