Struts2.2.1 execAndWait Interceptor example.
Posted on: January 29, 2011 at 12:00 AM
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.ADS_TO_REPLACE_1

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"ADS_TO_REPLACE_2

pageEncoding="UTF-8"%>

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

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

<html>

<head>

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

<title>Execute And Wait Interceptor</title>

</head>

<body>ADS_TO_REPLACE_5

<h1>Execute And Wait Interceptor</h1>

<hr>

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

</body>

</html>

2-WaitProcess.jsp

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

pageEncoding="UTF-8"%>

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

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

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

<html>

<head>ADS_TO_REPLACE_9

<meta http-equiv="refresh"

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

<title>Execute And Wait Interceptor</title>ADS_TO_REPLACE_10

</head>

<body>

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

</body>

</html>

3-ExecuteAndWaitAction.java

package roseindia.action;ADS_TO_REPLACE_12

import com.opensymphony.xwork2.ActionSupport;

public class ExecuteAndWaitAction extends ActionSupport{

public String execute() throws Exception {ADS_TO_REPLACE_13

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

{

System.out.println(i);ADS_TO_REPLACE_14

}

return SUCCESS;

}ADS_TO_REPLACE_15

}

4_struts.xml

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

<!DOCTYPE struts PUBLICADS_TO_REPLACE_16

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

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

<struts>ADS_TO_REPLACE_17

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

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

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

<interceptor-ref name="execAndWait">

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

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

</interceptor-ref>

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

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

</action>

</package>

</struts>

5_SuccessProcess.jspADS_TO_REPLACE_21

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

pageEncoding="UTF-8"%>

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

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

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

<html>ADS_TO_REPLACE_23

<head>

<title>Execute And Wait Interceptor</title>

</head>ADS_TO_REPLACE_24

<body>

Process completed successfully.... Thanks!

</body>ADS_TO_REPLACE_25

</html>

indexJsp.gif

WaitProcess.gifADS_TO_REPLACE_26

SuccessProcess.gif

ADS_TO_REPLACE_27

Download Select Source Code

Related Tags for Struts2.2.1 execAndWait Interceptor example.:

Advertisements

Ads

 
Advertisement null

Ads