我找到了一些关于禁用表单处理的提交按钮(以避免双重表单提交)的点点滴滴,但它对我的特定情况没有帮助:
假设我禁用了“提交”#39;在表单提交的jQuery中,
JS / jQuery的:
<script type="text/javascript">
$(document).ready(function() {
alert('In Document.ready');
// Initially enable the Submit button
$(this).find('input[type=submit]').prop('disabled', false);
$('#form').on('submit', function(e){
// Disable Submit button on form submit
$(this).find('input[type=submit]').prop('disabled', true);
});
});
</script>
表单HTML
<form id="form" method="post" action="/generate.do">
<label>Number</label><br/>
<input type="text" name="number" maxlength="50" value="" title="Enter Number">
<html:submit value="Go"/>
</form>
这样做 - 按钮被禁用。我在服务器端有一个Struts Action类来处理这个表单。
Struts Action结果是返回文件下载。我根据通常的Struts指南写入响应并获取我的另存为对话框
Struts Action:
InputStream is = getImageBytes();
response.setContentType("application/pdf");
response.addHeader("content-disposition", "attachment; filename=\"file.pdf\"");
// Write to Response Stream
OutputStream os = response.getOutputStream();
byte[] buffer = new byte[4096];
int length;
while ((length = is.read(buffer)) > 0)
{
os.write(buffer, 0, length);
}
is.close();
os.flush();
// Response was handled within the action, so set forward = null
forward = null;
问题:我从操作回来后,“提交”按钮没有重新启用,它仍处于禁用状态。我在回来时没有得到我的页面启动jQuery警告框,因此页面没有刷新。
我无法转发或发送重定向,我发现这些错误:
例如, (1)转发
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:328)
的
ActionForward forwardSuccess = mapping.findForward("success");
forwardSuccess.setRedirect(false);
return forwardSuccess;
(2)SendRedirect
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:494)
目标:目标是从服务器端操作返回文件下载结果,但在jQuery 中以某种方式拦截它以重新启用“提交”按钮结果回来的形式。