个性化阅读
专注于IT技术分析

Struts 2 execAndWait拦截器示例图解

点击下载
  1. ExecAndWait拦截器
  2. execAndWait拦截器的参数
  3. execAndWait拦截器的示例

execAndWait拦截器也称为执行和等待拦截器, 用于显示中间结果。

建议用于长时间运行的动作。

默认情况下, 它不在默认堆栈中。因此, 你需要明确指定它。

如果未指定”等待”结果, 则struts框架将显示中间结果, 直到你的请求完成。

对于定制的中间结果, 你需要在struts.xml文件中定义”等待”结果。在页面中, 你可以显示处理图像等。因此, 最好指定自定义结果。

execAndWait拦截器的参数

为execAndWait拦截器定义了3个参数。

Parameter Description
delay 指定初始延迟时间。默认情况下, 未设置初始延迟。
delaySleepInterval 仅延迟使用。它指定以毫秒为单位的时间间隔, 以检查后台进程是否完成。默认情况下, 它设置为100毫秒。
threadPriority 指定线程的优先级。默认值为Thread.NORM_PRIORITY。

没有等待结果的execAndWait拦截器示例

让我们看一下没有等待结果的execAndWait拦截器的简单示例。在这种情况下, struts框架会提供中间结果。

<action name="login" class="com.srcmini.Login">
    <interceptor-ref name="params"/>
    <interceptor-ref name="execAndWait"/>
    <result name="success">login-success.jsp</result>
</action>

具有等待结果的execAndWait拦截器示例

让我们看一下带有等待结果的execAndWait拦截器的简单示例。在这种情况下, 将调用你的中间页面。

<action name="login" class="com.srcmini.Login">
    <interceptor-ref name="params"/>
    <interceptor-ref name="execAndWait"/>
    <result name="success">login-success.jsp</result>
    <result name="wait">myintermediatepage.jsp</result>
</action>

myintermediatepage.jsp

让我们编写中间结果的代码。 s:url标记会将请求转发到指定的url。

<%@ taglib uri="/struts-tags" prefix="s" %>
<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="processing.gif"/>

</body>
</html>

它将在0.5秒后刷新。

下载完整示例(在Eclipse IDE中开发)

输出

struts 2 execandwait示例输出1
struts 2 execandwait示例输出2
struts 2 execandwait示例输出3
struts 2 execandwait示例输出4
赞(0)
未经允许不得转载:srcmini » Struts 2 execAndWait拦截器示例图解

评论 抢沙发

评论前必须登录!