调用 execAndWait 拦截器后重定向到未在 struts.xml 操作中定义的页面

Getting redirected to page which is not defined in struts.xml action after calling execAndWait interceptor

将文件上传到服务器后,服务器会进行一些处理,这需要一些时间。因此我使用执行和等待拦截器来防止超时。

但问题是,一旦调用 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>

操作class

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 拦截器并将 defaultStack 替换为 completeStack 拦截器。

 <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>