我想在请求花费太多时间编写html文件时将处理栏放在我的页面上。所以我在Strust2中使用了execAndWait
拦截器,但是页面无法在wait.jsp上重定向。
Struts.xml
<action name="htmlUtility"
class="com.support.action.ActivityAction" method="htmlUtility">
<interceptor-ref name="execAndWait">
<param name="delay">1000</param>
<param name="delaySleepInterval">500</param>
</interceptor-ref>
<result name="wait">/pages/reportingview/ftl/wait.jsp</result>
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${filename}"</param>
<param name="bufferSize">1024</param>
</result>
</action>
Wait.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>wait</title>
<meta http-equiv="refresh" content="0.5;url='<s:url includeParams="all" />'">
</head>
<body>
<p>your request is processing...</p>
<img src="ajax-loader.gif"/>
</body>
</html>
ActivityAction -
private InputStream saveAsHTML() {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PrintStream printhtml = new PrintStream(buffer);
String htmlheader="<html><style type='text/css'>.dataTable "
+ "{width:100%; font-family:Verdana, Geneva, sans-serif;border-top:1px solid #ccc; border-right:1px solid #ccc;+}"
+ ".dataTable th {background:#f1f1f1; text-align:left;padding:5px;font-weight:normal; border-bottom:1px solid #ccc;"
+ " border-left:1px solid #ccc;}.dataTable tr {}.dataTable td { padding:5px;border-bottom:1px solid #ccc;border-left:1px solid #ccc;}.txtCenterAlign "
+ "{text-align:center !important;}.transparentBg{ background:transparent !important;}</style><head>";
if(activityType.equalsIgnoreCase(SupportWebConstants.ACCESSPOINT_CONSTANT)){
htmlheader+="<title>Access Point Activity Report</title></head><body> <table width='100%' border='0' cellpadding='0' cellspacing='0' class='dataTable'><thead> <tr>"
+ "<th colspan='9' class='txtCenterAlign'>Access Point Activity Report</th></tr><tr>";
}
else
{
htmlheader+="<title>Credential Holder Activity Report</title></head><body> <table width='100%' border='0' cellpadding='0' cellspacing='0' class='dataTable'><thead> <tr>"
+ "<th colspan='9' class='txtCenterAlign'>Credential Holder Activity Report</th></tr><tr>";
}
for (String columnName : ReportHeaderMapper.getColumnList(activityType)) {
htmlheader+= "<th class='transparentBg'><b>"+columnName+"</b></th>";
}
htmlheader+="</tr></thead> <tbody>";
String tableData="";
String htmlfooter=" </tbody></body></html>";
activityList = activityDTOList.getActivityDTOs();
ReportHeaderMapper.setData(activityList);
for (List<String> activityDTO : ReportHeaderMapper.getAccessPointAllRows(activityType)) {
tableData= tableData+"<tr>";
for (String data : activityDTO) {
tableData+= "<td>"+data+"</td>";
}
tableData=tableData+"</tr>";
}
printhtml.println(htmlheader+tableData+htmlfooter);
printhtml.close();
LOGGER.info("HTML file created successfully.");
LOGGER.info("HTML activityList size" + activityList.size());
return new ByteArrayInputStream(buffer.toByteArray());
}
当我生成请求时,我得到以下错误
HTTP状态404 - 没有为操作定义结果 com.narendra.stg.Sdg.support.action.ActivityAction和结果错误
输入状态报告
消息没有为操作定义结果 om.narendra.stg.Sdg.support.action.ActivityAction和结果错误
说明请求的资源不可用。
答案 0 :(得分:1)
由于某种原因,您的操作返回“错误”作为结果类型。
检查返回错误的原因,可能是在方法执行之前它在返回成功之前的意外。
还要将返回名称添加为错误并重定向到某个error.jsp页面,这就是您的错误所在
没有为行动定义任何结果 com.narendra.stg.Sdg.support.action.ActivityAction和结果错误
答案 1 :(得分:1)
执行操作所需的默认拦截器堆栈。当覆盖拦截器时,您不包括defaultStack
。请尝试以下操作配置
<action name="htmlUtility"
class="com.assaabloy.stg.support.ActivityAction" method="htmlUtility">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait">
<param name="delay">1000</param>
<param name="delaySleepInterval">500</param>
</interceptor-ref>
<result name="wait">/pages/reportingview/ftl/wait.jsp</result>
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${filename}"</param>
<param name="bufferSize">1024</param>
</result>
</action>
应该有一个拦截器返回error
结果,这个结果可以像this answer一样全局配置。