Page does not reload after form submit when a file is offered for download

时间:2017-10-12 09:58:00

标签: javascript java html jsp servlets

On a website there is a form which will send a request to a Java servlet:

<form class="export" 
      action="export_data" 
      method="post" 
      enctype="application/x-www-form-urlencoded"> 
  <input type="image" 
         src="images/btn_export_data.png" 
         name="operation" value="export" />
  <!-- checkboxes of various data exporters -->
</form>

The servlet processes the request and offers a file to download. After that I expect the page to reload - but it doesn't. What could be the cause?


Things I've tried so far - without success:

Set a redirect in the servlet

response.sendRedirect( "/content/export_data.jsp" );

Set a forward in the servlet

  // request is the HttpServletRequest
  // response is the HttpServletResponse
  // httpServlet is the HttpServlet
  final HttpSession currentSession = request.getSession();
  final RequestDispatcher requestDispatcher =
        httpServlet.getServletContext().getRequestDispatcher( "/content/export_data.jsp" );
  currentSession.setAttribute( "target", "/content/export_data.jsp" );
  requestDispatcher.forward( request, response );

Set the onsubmit event in the page

onsubmit="window.location.reload();"

0 个答案:

没有答案