在很多程序请求是都有等待的页面!
在WebWork2.1.1开始,就新增了一个拦截器:execAndWait
<interceptor name="execAndWait" class="com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor"/>
execAndWait将请求的Action放到后台执行,同时返回"wait"的输出结果;再次同样的Action请求,如果Action执行完毕,它将返回
真正的输出结果。
注意:"wait"输出等待页面时必须包含下面语句:
<meta http-equiv="refresh" content="5;url="<ww:url includeParams="'all'" />">
它每隔5秒钟,重新刷新前面的action请求。
Example:
// WaitAction.java
package example.wait;
import com.opensymphony.xwork.Action;
public class WaitAction implements Action{
public String execute() throws Exception {
try {
System.out.println("-----start sleep!");
Thread.sleep(2000 * 10);
System.out.println("-----end sleep!");
} catch (InterruptedException e) {
e.printStackTrace();
}
return SUCCESS;
}
}
xwork.xml:
<action name="wait" class="example.wait.WaitAction">
<result name="success" type="dispatcher">
<param name="location">/success.jsp</param>
</result>
<result name="wait" type="dispatcher">
<param name="location">/wait.jsp</param>
</result>
<interceptor-ref name="execAndWait"/>
</action>
wait.jsp:
<%@ taglib uri="webwork" prefix="ww" %>
<HTML>
<HEAD>
<meta http-equiv="refresh" content="5;url="<ww:url includeParams="'all'" />">
</HEAD>
<BODY>
Wait..............
</BODY>
</HTML>
posted on 2006-11-08 17:13
larryjava 阅读(455)
评论(0) 编辑 收藏