上传文件到服务器后,服务器会做一些处理,这需要一些时间。因此,我使用执行和等待拦截器来防止超时。
但问题是,一旦execAndWait被调用页面被重定向到exception.jsp,但在服务器端,我根本没有得到任何异常。服务器端进程运行正常
在struts.xml中也没有为exception.jsp定义结果。
Struts.xml
<action name="Process" class="fpoActions.Process" method="execute">
<interceptor-ref name="defaultStack">
<param name="fileUpload.maximumSize">150971520</param>
</interceptor-ref>
<interceptor-ref name="completeStack" />
<interceptor-ref name="execAndWait" />
<result name="wait">WEB-INF/fpo/longRunningAction-wait.jsp</result>
<result name="success">WEB-INF/fpo/DownloadFpo.jsp</result>
<result name="input">WEB-INF/fpo/fpoAnalysis.jsp</result>
</action>
操作类public String execute(){
String appPath=request.getServletContext().getRealPath("")+"\WEB-INF\Data";
try{
System.out.println("DestinationLoc:"+appPath);
System.out.println("Source File Name:"+fileFileName);
File destFile = new File(appPath, fileFileName);
System.out.println(month+" "+year);
FileUtils.copyFile(file, destFile);
System.out.println("File Copied");
System.out.println(destFile.getAbsolutePath());
System.out.println(appPath);
String t=utils.LogUtils.generateData(month,year,appPath,destFile.getAbsolutePath(),appPath);
System.out.println("OutPut:"+t);
System.out.println(new File(t).exists());
}catch(Exception ex){
addActionMessage("User Attributes file is not valid!!");
ex.printStackTrace();
return "input";
}
return "success";
}
longRunningAction-wait.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Processing</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style type="text/css">
div#header,div#footer,div#content,div#post {
border:1px solid grey;
margin:5px;margin-bottom:5px;padding:8px;
background-color:white;
}
div#header,div#footer {
color:white;background-color:#444;margin-bottom:5px;
}
div#footer {
position:fixed;
left:0px;
bottom:0px;
height:30px;
width:100%;
background:#444;
}
.logoutLblPos{
position:fixed;
left:10px;
top:5px;
}
</style>
</head>
<body>
<div id="header">
<h1 align="center"> Automation</h1>
</div>
<div class="container">
<h2 align="center">Please Wait while we process your Data...</h2>
<div class="progress" align="center">
<div align="center" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
40%
</div>
</div>
</div>
<div id="footer">
</div>
</body>
</html>
在struts.xml中进行以下更改后问题解决
删除了completeStack拦截器,并用completeStack拦截器替换了defaultStack。
<action name="Process" class="fpoActions.Process" method="execute">
<interceptor-ref name="completeStack">
<param name="fileUpload.maximumSize">150971520</param>
</interceptor-ref>
<interceptor-ref name="execAndWait" />
<result name="wait">WEB-INF/fpo/longRunningAction-wait.jsp</result>
<result name="success">WEB-INF/fpo/DownloadFpo.jsp</result>
<result name="input">WEB-INF/fpo/fpoAnalysis.jsp</result>
</action>