Home Struts Struts Struts2.2.1 Struts2.2.1 execAndWait Interceptor example.

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 execAndWait Interceptor example.
Posted on: January 29, 2011 at 12:00 AM
Advertisement
In this example, we will disscuss about the Execute and wait (execAndWait) Interceptor using struts2.2.1.

Struts2.2.1  execAndWait Interceptor example.

In this example, we will disscuss about the Execute and wait (execAndWait)  Interceptor using struts2.2.1. 

The Execute and Wait Interceptor is used for the long running actions in the background of the process and user will show a custom web-page or progress bar. The Execute and Wait Interceptor is very usefull to prevent the HTTP request from timing out during the execution of the action which takes long time(more than 5 or 10 mints) to be completed. 

This Interceptor is used as the last Interceptor of the Interceptor Stack and this is works on the per-session basis i.e. the actions with the same name can not run more than once at a time period in the given session. on any subsequent or initial request before the completion of  action, The wait result is returned. The wait result is responsible for the generating a request to the action back. and when the process is completed then success result  displayed.

In the given example of  Execute And Wait Interceptor we will wait for the 2 seconds before the wait page is displayed to the user. and after every 500 milisec the execAndWait Interceptor will check for that the process is completed or not,if not than remain waiting otherwise it redirect to success action.

Directory structure of execAndWait Interceptor example.

 1- index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Execute And Wait Interceptor</title>

</head>

<body>

<h1>Execute And Wait Interceptor</h1>

<hr>

<a href="ExecuteAndWaitAction.action">Execute And Wait Interceptor</a>

</body>

</html>

2-WaitProcess.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@taglib prefix="s" uri="/struts-tags"%>

<html>

<head>

<meta http-equiv="refresh"

content="5; url=<s:url includeParams="all" />"></meta>

<title>Execute And Wait Interceptor</title>

</head>

<body>

Process executing please wait.............

</body>

</html>

3-ExecuteAndWaitAction.java

package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;

public class ExecuteAndWaitAction extends ActionSupport{

public String execute() throws Exception {

for(int i=0;i<50000;i++)

{

System.out.println(i);

}

return SUCCESS;

}

}

4_struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.devMode" value="true" />

<package name="default" namespace="/" extends="struts-default">

<action name="ExecuteAndWaitAction" class="roseindia.action.ExecuteAndWaitAction">

<interceptor-ref name="execAndWait">

<param name="delay">2000</param>

<param name="delaySleepInterval">500</param>

</interceptor-ref>

<result name="wait">JSP/WaitProcess.jsp</result>

<result name="success">JSP/SuccessProcess.jsp</result>

</action>

</package>

</struts>

5_SuccessProcess.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@taglib prefix="s" uri="/struts-tags"%>

<html>

<head>

<title>Execute And Wait Interceptor</title>

</head>

<body>

Process completed successfully.... Thanks!

</body>

</html>

indexJsp.gif

WaitProcess.gif

SuccessProcess.gif

Download Select Source Code

Related Tags for Struts2.2.1 execAndWait Interceptor example.:


DMCA.com