当请求花费太多时间来编写 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>
等待.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>
活动动作:
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 和结果错误
描述 请求的资源不可用。
由于某种原因,您的操作返回“错误”作为结果类型。
检查返回错误的原因,可能是方法执行过程中失败,然后才返回成功。
还添加返回名称作为错误并重定向到某个 error.jsp 页面,这就是您的错误所说的
没有为操作定义结果 com.narendra.stg.Sdg.support.action.ActivityAction 和结果错误
执行操作所需的默认拦截器堆栈。当重写拦截器时,您没有包含
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答案中那样全局配置该结果。