zoukankan      html  css  js  c++  java
  • struts2拦截器execAndWait

    1、在struts.xml
    <action name="register" class="com.abc">
    <interceptor-ref name="defaultStack"></interceptor-ref>
          <interceptor-ref name="execAndWait">
          <param name="excludeMethods">input</param>
          <!-- 等待时间,执行时间没有超过此值,将不显示等待画面 (毫秒)
          <param name="delay">1000</param>-->
          <!-- 间隔检查时间,检查后台进程有没有执行完毕,如果完成了它就立刻返回,不用等到等待,用户不会看到等待画面
          <param name="delaySleepInterval">50</param>-->
          </interceptor-ref>
    </action>

    @Override
     public String execute() throws Exception
     {
      while(process<total){
      process++;
      Thread.sleep(900);
      System.out.println(process);
      }
      return SUCCESS;
     }
    2、增加result
           <result name="wait">wait.jsp</result>
    3、<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> 
    <%@taglib prefix="s"uri="/struts-tags"%> 
    <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"> 
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
    <meta http-equiv="refresh" content="1;url=<s:url includeParams="none" />"/> 
    <title>
    </title>
    </head>
    <body>
    <h1>数据处理中,请稍等......</h1>
    process:${process }  total:${total }
    <br>
    如果没有自动跳转请<a href="<s:url includeParams="all" />">点这里</a>.
    其中的includeParams参数取值为:<br>
    none,不把参数加入到url参数中<br>
    all,是把get和post中的参数加入到url参数中<br>
    get,是只把get中的参数加入到url参数中
    </body>
    </html>

    4、Action实现SessionAware接口

           因为这个action将会以单独的线程执行,所以你不能用ActionContext,因为它是ThreadLocal.这也就是说如果你要访问session数据,你必须实现 SessionAware结构而不是调用ActionContext.getSesion() 。

           public interface SessionAware{
                  public void setSession(Map map);
           }

           public abstract class AbsBasicAction extends ActionSupport implements SessionAware{
                 
                   /** 当前 Session */
                  protected Map session ;

                  public void setSession(Map session) {
                       this.session = session ;
                  }
           }
  • 相关阅读:
    python邮件之附件
    python3.5之smtp
    一台Linux上搭建两个tomcat
    mysql 初探(一)
    python监视mysql最大连接数
    P3658 [USACO17FEB]Why Did the Cow Cross the Road III P cdq分治
    P4793 [AHOI2008]矩形藏宝地 cdq分治 线段树
    P2487 [SDOI2011]拦截导弹 线段树 cdq分治
    P3157 [CQOI2011]动态逆序对 cdq分治
    P4169 [Violet]天使玩偶/SJY摆棋子 cdq分治
  • 原文地址:https://www.cnblogs.com/jamin/p/1569127.html
Copyright © 2011-2022 走看看