Search code examples
javastruts2struts2-interceptors

Execute and Wait Interceptor in struts2


I'm getting an error i.e
WARNING: Could not find token mapped to token name token
I didn't understand please tell me why I'm getting this error and how to resolve it.
struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>

    <package name="interceptorExecAndWait" extends="struts-default">
        <action name="execAndWaitInterceptor" class="com.interceptor.execandwait.action.ExecuteAndWait">
            <!-- <interceptor-ref name="defaultStack"/>  -->
            <interceptor-ref name="completeStack"/>
                    <interceptor-ref name="execAndWait">    
                                    <param name="delay">1000</param>    
                    </interceptor-ref>  
            <!-- <interceptor-ref name="execAndWait"/> -->
            <result name="success">/welcome.jsp</result>
            <result name = "wait">/wait.jsp </result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
</struts>

ExecuteAndWait.java

public class ExecuteAndWait {

    String userName;
    String password;

    public String execute() throws InterruptedException {

        if (userName.equals("Admin") && password.equals("user")) {
            System.out.println("ok");
            Thread.sleep(5000);
            return "success";
        } else {
            return "error";
        }
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


}

Let me know where I make mistakes
Thanks :)


Solution

  • Add

    <interceptor-ref name="completeStack"/>
                  <interceptor-ref name="execAndWait">
                    <param name="delay">1000</param>
                    <param name="delaySleepInterval">500</param>
                </interceptor-ref>
    

    in your struts.xml i.e.,

    <package name="interceptorExecAndWait" extends="struts-default">
            <action name="execAndWaitInterceptor" class="com.interceptor.execandwait.action.ExecuteAndWait">
                  <interceptor-ref name="completeStack"/>
                  <interceptor-ref name="execAndWait">
                    <param name="delay">1000</param>
                    <param name="delaySleepInterval">500</param>
                </interceptor-ref>
                <result name="success">/welcome.jsp</result>
                <result name = "wait">/wait.jsp </result>
                <result name="error">/error.jsp</result>
            </action>
        </package>
    

    Include the includeParams="all" and http-equiv="Refresh" in the meta tag, in your wait.jsp i.e.,

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Refresh" content="5;url=<s:url includeParams="all" />">
    <title>Waiting</title>
    </head>
    <body>
    
        <div align="center">
            <h2>Please wait while we verify your credentials.. </h2>
        </div>
    
    </body>
    </html>