Javascript 当提供文件供下载时,表单提交后页面不会重新加载
在网站上,有一个表单将向Java servlet发送请求:Javascript 当提供文件供下载时,表单提交后页面不会重新加载,javascript,java,html,jsp,servlets,Javascript,Java,Html,Jsp,Servlets,在网站上,有一个表单将向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="operati
<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>
在servlet中设置转发
response.sendRedirect( "/content/export_data.jsp" );
// 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 );
在页面中设置onsubmit事件
onsubmit="window.location.reload();"
尝试将
onClick
添加到按钮onClick=“setTimeout(function(){window.location.reload()},100)”
这不起作用。您可以粘贴servlet的代码吗?您对哪个部分感兴趣?servlet有几千行。我感到惊讶的是,posted forward解决方案(“在servlet中设置一个forward”)可以与此webapp中的所有其他表单一起使用,但不能与提供文件下载的表单一起使用。在网站本身上,onSubmit
事件似乎被禁用,因为我甚至不能用普通JavaScript启动一个警报框。尝试将onClick
添加到按钮onClick=“setTimeout(function(){window.location.reload()},100)”
这不起作用。你能粘贴servlet的代码吗?你对哪个部分感兴趣?servlet有几千行。我感到惊讶的是,posted forward解决方案(“在servlet中设置一个forward”)可以与此webapp中的所有其他表单一起使用,但不能与提供文件下载的表单一起使用。在网站本身上,onSubmit
事件似乎已被禁用,因为我甚至无法使用纯JavaScript启动警报框。