Execute and Wait Interceptors in Struts 2.x

Today, in this post you are going to know or have knowledge about “Execute and Wait Interceptors in Struts 2.x”.The time is taken by the action, it takes a longer amount of time and We want to display or show a “waiting icon” or “some waiting message” page during this whole waiting process until the action gets completed and returns true from execute() method We can use this type of interceptors.

Execute and Wait Interceptors should be placed at the bottom of the action result declaration and after any other interceptors if present or in case of default interceptor too as Execute and Wait interceptors will/can prevent other interceptors to perform their work.

5000

@param delay: Specifies the duration after which the “wait” message page should be displayed. 

50

@param delaySleepInterval: Specifies the duration after which a check for action completion is made. It has default time value of 100ms.
Working Example of Execute and Wait Interceptor:

1. Create an index.jsp page
Write the following code there:

Click me

Remember: It will work for Struts 2.x Projects and make sure you have included the taglib directory of Struts 2.x in the index.jsp.

If you have not included it do it now, write the following code for HTML tag:

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

2. Create a welcome page e.g. welcome.jsp having A welcome message.

3. Create a jsp page which you want to show while the background process is going on e.g: wait.jsp
Write the following code there in wait.jsp


include this above title tag of page.

4. Make configurations in struts.xml

2000
50 
wait.jsp
welcome.jsp 

5. Create a package action and in that package create a class Call.java
Write the following code inside the Call i.e. class body there:

public String execute() throws Exception{
Thread.sleep(5000);
return "success"; 
}

That’s it… You application or program is ready to provide you the the functionality to display visitors a waiting page while performing background process which generally takes time like database queries, handling registration forms, login, etc.