ExecuteAndWait Interceptor Example in Struts 2.0
ExecuteAndWait Interceptor Example in Struts 2.0
ExecuteAndWait Interceptor Example using Struts 2.0 the following tool are required for run this example
- JDK 1.5
- MyEclipse IDE
- Server Tomcat 6.0
- Struts 2.0 jar file
Directory Structure of ExecuteAndWait Example in Struts 2.0 Using MyEclipse IDE
index.jsp
<%@taglib uri="/struts-tags" prefix="s"%>
<s:form action="exewait" >
<s:textfield name="name" label="Name"/>
<s:submit value="Submit"/>
</s:form>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="exewait" class="mypack.ExecuteAction">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<result name="success">/result.jsp</result>
<result name="wait">/progress.jsp</result>
</action>
</package>
</struts>
ExecuteAction.java
package mypack;
public class ExecuteAction {
String name;
public String execute(){
try{
Thread.sleep(10000);
}catch(Exception e){}
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
process.jsp
<meta http-equiv="refresh" content="4;">
<b>Work is progressing</b>
result.jsp
<%@taglib uri="/struts-tags" prefix="s"%>
Welcome, <s:property value="name"/><br/>
<b>Your wait is completed</b>
Output
