Struts 2 execAndWait interceptor example


The execAndWait interceptor otherwise called execute and hold up interceptor is utilized to show the middle result.

It is prescribed to use for long running action.

It isn't found in the default stack bydefault. So you have to indicate it explicitely.

If you don't indicate "wait" result, swaggers structure shows a middle of the road result until your solicitation is completed.

For the custom moderate outcome, you have to characterize "pause" result in struts.xml record. In your page, you can show preparing picture and so on. Along these lines, it is smarter to determine the custom result.

Parameters of execAndWait interceptor

There are 3 parameters characterized for execAndWait interceptor.

ParameterDescription
delay determines the underlying defer time. Bydefault, no underlying postponement is set.
delaySleepInterval utilized just with postponement. It determines the time interim in milliseconds to watch that foundation procedure is finished. It is set to 100 milliseconds bydefault.
threadPriority determines the need of the string. The default is Thread.NORM_PRIORITY.

Example of execAndWait interceptor without hold up result

Let's see the straightforward case of execAndWait interceptor without hold up result. In such case, swaggers structure gives a middle of the road result.

  1. <action name="login" class="com.javatpoint.Login">  
  2.     <interceptor-ref name="params"/>  
  3.     <interceptor-ref name="execAndWait"/>  
  4.     <result name="success">login-success.jsp</result>  
  5. </action>  

Example of execAndWait interceptor with hold up result

Let's see the basic case of execAndWait interceptor with hold up result. In such case, your middle of the road page is invoked.

  1. <action name="login" class="com.javatpoint.Login">  
  2.     <interceptor-ref name="params"/>  
  3.     <interceptor-ref name="execAndWait"/>  
  4.     <result name="success">login-success.jsp</result>  
  5.     <result name="wait">myintermediatepage.jsp</result>  
  6. </action>  

myintermediatepage.jsp

Let's compose the code for halfway outcome. The s:url label will advance the solicitation to indicated url.

  1. <%@ taglib uri="/swaggers tags" prefix="s" %>  
  2. <html>  
  3. <head>  
  4. <title>wait</title>  
  5.   
  6. <meta http-equiv="refresh" content="0.5;url='<s:url includeParams="all" />'">  
  7. </head>  
  8. <body>  
  9.   
  10. <p>your request is processing...</p>  
  11. <img src="processing.gif"/>  
  12.   
  13. </body>  
  14. </html>  





javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition