使用execAndWait拦截器可以在等待较长时间的后台处理中增加等待页面。实现如下图所示的效果:

  1)struts.xml主要部分

<action name="test" class="actions.ActionDemo" method="queryall">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait">
<!-- 等待时间,执行时间没有超过此值,将不显示等待画面 (毫秒)-->
<param name="delay">1000</param>
<!-- 间隔检查时间,检查后台进程有没有执行完毕,如果完成了它就立刻返回,不用等到等待,用户不会看到等待画面 -->
<param name="delaySleepInterval">50</param>
</interceptor-ref>
<result name="wait">/wait.jsp</result>
<result name="success">/rs.jsp</result>
</action>

  2)action主要部分

public String queryall(){

        for (int i = 0; i <; i++) {
System.out.println(i);
}
user = "你好";
this.setListData();
return Action.SUCCESS;
}

  3)jsp页面取值部分(rs.jsp)

  List list =  (List)request.getAttribute("listall"); 取值OK

  4)等待页面部分(wait.jsp)

<%@ page contentType="text/html; charset=GBK" language="java"
errorPage=""%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=Content-Type content="text/html;charset=gbk">
<META HTTP-EQUIV="Refresh" content="2;url=<s:url includeParams="all"/>"/>
<title> 正在查询,请稍等...</title>
<style type="text/css">
.query_hint{
border:5px solid #939393;
width:250px;
height:50px;
line-height:55px;
padding:0 20px;
position:absolute;
left:50%;
margin-left:-140px;
top:50%;
margin-top:-40px;
font-size:15px;
color:#333;
font-weight:bold;
text-align:center;
background-color:#f9f9f9;
}
.query_hint img{position:relative;top:10px;left:-8px;}
</style>
</head> <body>
<div id="query_hint" class="query_hint">
<img src="http://files.cnblogs.com/ningvsban/waiting.gif" />正在查询,请稍<s:url includeParams="all"/>等...
</div>
<!--
<a href="<s:url includeParams="all" />"> 点这里 </a> 如果没有自动跳转请点击这里.
-->
</body>
</html>

  关于<meta http-equiv="refresh" content="0;url= "/>的几点说明:

  1)该句话用于页面定期刷新,如果加url的,则会重新定向到指定的网页,content后面跟的是时间(单位秒),把这句话加到指定网页的<head></head>里一般也用在实时性很强的应用中,需要定期刷新的页面,如新闻页面,论坛等,不过一般不会用这个,都用新的技术比如ajax等。

  2)对于wait.jsp中的<meta http-equiv="refresh" content="2;url=<s:url includeParams="all"/> "/>意思为:每隔2秒自动刷新定位到目标页面。

  3)对于<s:url includeParams="all"/>为struts2的标签<s:url>,详细请点击这里

  参考资料:http://blog.csdn.net/yirentianran/article/details/3392314

【struts2】struts2的execAndWait拦截器使用的更多相关文章

  1. struts2的execAndWait拦截器

    struts2中有许多默认拦截器,这里我们看一下execAndWait拦截器. 当一个页面需要加载一段时间的时候,我们希望它不是一直呆在原页面直到加载完成,而是进入等待页面,加载完毕后自动进入目标页面 ...

  2. 【struts2】预定义拦截器

    1)预定义拦截器 Struts2有默认的拦截器配置,也就是说,虽然我们没有主动去配置任何关于拦截器的东西,但是Struts2会使用默认引用的拦截器.由于Struts2的默认拦截器声明和引用都在这个St ...

  3. 使用struts2中默认的拦截器以及自定义拦截器

    转自:http://blog.sina.com.cn/s/blog_82f01d350101echs.html 如何使用struts2拦截器,或者自定义拦截器.特别注意,在使用拦截器的时候,在Acti ...

  4. Struts2基础学习(五)—拦截器

    一.概述 1.初识拦截器      Interceptor 拦截器类似前面学过的过滤器,是可以在action执行前后执行的代码,是我们做Web开发经常用到的技术.比如:权限控制.日志等.我们也可以将多 ...

  5. 33.使用默认的execAndWait拦截器

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 当我们进行数据库查询等相关的操作时,如果服务器负荷过重可能不能及时把数据查询 ...

  6. Struts2入门(二)——配置拦截器

    一.前言 之前便了解过,Struts 2的核心控制器是一个Filter过滤器,负责拦截所有的用户请求,当用户请求发送过来时,会去检测struts.xml是否存在这个action,如果存在,服务器便会自 ...

  7. 【Java EE 学习 69 上】【struts2】【paramsPrepareParamsStack拦截器栈解决model对象和属性赋值冲突问题】

    昨天有同学问我问题,他告诉我他的Action中的一个属性明明提供了get/set方法,但是在方法中却获取不到表单中传递过来的值.代码如下(简化后的代码) public class UserAction ...

  8. Struts2 源码分析——拦截器的机制

    本章简言 上一章讲到关于action代理类的工作.即是如何去找对应的action配置信息,并执行action类的实例.而这一章笔者将讲到在执行action需要用到的拦截器.为什么要讲拦截器呢?可以这样 ...

  9. Struts2学习笔记(拦截器配置添加)

    一.拦截器工作原理: 根据Struts2的工作原理图,拦截器在action执行前进行顺序调用,之后执行Action并返回结果字符串,再逆序调用拦截器.(结构类似递归方式...)大部分时候,拦截器方法都 ...

随机推荐

  1. CMake can't find GLEW

      Q: I'm on Windows and there is a FindGLEW.cmake file in my CMake modules folder, presumably put th ...

  2. cmake 学习笔记(三) (转)

    接前面的 Cmake学习笔记(一) 与 Cmake学习笔记(二) 继续学习 cmake 的使用. 学习一下cmake的 finder. finder是神马东西? 当编译一个需要使用第三方库的软件时,我 ...

  3. Downloading jQuery 3.2.1

    Downloading jQuery Compressed and uncompressed copies of jQuery files are available. The uncompresse ...

  4. GOOD BLOG URL

    1TEST http://www.cnblogs.com/Javame/p/3653509.html 综合 http://shiyanjun.cn/

  5. C#.NET常见问题(FAQ)-如何使用DataGridView跟Excel数据交互

    1 从工具箱中拖进来一个DataGridView   2 就像Excel表头,可以添加一个表头(即一列的抬头,比如叫做A)   3 一次添加ABCDE等项目,也可以修改该类目的类型为Button或者C ...

  6. springboot项目中报错:listener does not currently know of SID given in connect descriptor

    springboot项目中报错:listener does not currently know of SID given in connect descriptor 出现这个问题的原因是SID写错了 ...

  7. archivedDataWithRootObject NSUserDefaults

    archivedDataWithRootObject 存储 BusinessCard *bc = [[BusinessCard alloc] init];   NSUserDefaults *ud = ...

  8. asp.net 定时执行任务代码 定时采集数据

    using System; using System.Data; using System.Configuration; using System.Collections; using System. ...

  9. C# Directory.GetFiles()获取多个类型格式的文件

    第一种方式 System.IO.Directory.GetFiles()获取多个类型格式的文件 System.IO.Directory.GetFiles("c:\","( ...

  10. Nginx+Tomcat+Memcached 实现集群部署时Session共享

    Nginx+Tomcat+Memcached 实现集群部署时Session共享 一.简介 我们系统经常要保存用户登录信息,有Cookie和Session机制,Cookie客户端保存用户信息,Sessi ...