execAndWait in Struts Example

execAndWait is one of the default-Interceptor in Struts (you can view default-interceptors here). The execAndWait interceptor shows an intermediate webpage when result page is loading.

Structure of Project:
structure

Create 3 JSP files – login.jsp,loading.jsp,Success.jsp

login.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login Page</title>
    </head>
    <body>
        <s:form action="login">
            <s:textfield name="name" label="Username"/>
            <s:textfield type="password" name="pass" label="Password"/>
            <s:submit value="Login"/>
        </s:form>
    </body>
</html>

loading.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="refresh"  content="0.5;">
        <title>JSP Page</title>
    </head>
    <body>
        <h1><i>Loading...</i></h1>
    </body>
</html>

Success.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Success!!!</h1>
    </body>
</html>

dao.java

package Dao;

import com.opensymphony.xwork2.ActionSupport;

public class dao extends ActionSupport {
    String name,password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public String execute()
    {
        return "success";
    }
}

Struts.xml

<struts>
    <include file="example.xml"/>
    <!-- Configuration for the default package. -->
    <package name="default" extends="struts-default">
        <action name="login" class="Dao.dao">
            <interceptor-ref name="params"/>  
            <interceptor-ref name="execAndWait"/>  
            <result name="success">Success.jsp</result>  
            <result name="wait">loading.jsp</result>  
        </action>
    </package>
</struts>

Output:
login
loading
success

 

 

 

 

 

By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *