<action name="register" class="com.abc"> <interceptor-ref name="defaultStack"></intercep"/> <action name="register" class="com.abc"> <interceptor-ref name="defaultStack"></intercep"/>
歡迎您光臨本站 註冊首頁

struts2攔截器execAndWait

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

1、在struts.xml<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

<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"-//W<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />3C//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,是把getpost中的參數加入到

url參數中<br>

get,是只把get中的參數加入到url參數中

</body>

</html>

4Action實現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 ;

}

}


[火星人 ] struts2攔截器execAndWait已經有651次圍觀

http://coctec.com/docs/java/show-post-60960.html