struts2的execAndWait拦截器

时间:2023-03-08 22:09:23

struts2中有许多默认拦截器,这里我们看一下execAndWait拦截器。

当一个页面需要加载一段时间的时候,我们希望它不是一直呆在原页面直到加载完成,而是进入等待页面,加载完毕后自动进入目标页面。这时候我们就可以使用execAndWait拦截器了。

使用execAndWait三个参数:

threadPriority: 线程优先分配,默认值是Thread.NORM_PRIORITY

delay: 等待时间,如果页面加载小于这个时间,不显示等待页面

delaySleepInterval: 间隔检查时间,默认是100毫秒

注意几个关键点:

首先使用execAndWait的等待页面要设置多久自动刷新。

<meta http-equiv="refresh" content="5;url=<s:url includeParams='all' />"/>

其次在引用这个拦截器的时候拦截器的放置位置应该为所有拦截器的最后一个

demo:

<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait">
<param name="delay">1000<param> <!---wait页面延迟时间,可省略--->
<param name="delaySleepInterval">50<param><!----检查后天进行是否执行完成的时间可省略--->
<interceptor-ref>
<result name="wait">/wait.jsp</result><!---等待时候显示的页面--->
<result name="success">/welcome.jsp</result> <html>
<head>
<title>Please wait</title>
<meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />"/>
</head>
<body>
Please wait while we process your request.
Click <a href="<s:url includeParams="all" />">go</a> if this page does not reload automatically.
</body>
</html>