在 struts2 中执行并等待拦截器
Execute and Wait Interceptor in struts2
我收到一个错误,即
警告:找不到映射到令牌名称令牌的令牌
我不明白,请告诉我为什么会出现此错误以及如何解决它。
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;
}
}
让我知道哪里出错了
谢谢:)
您没有显示 refresh
元标记,但它可能不包含 <s:url>
标记中的 includeParams="all"
,例如
<head>
<title>Please wait</title>
<meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />"/>
</head>
添加
<interceptor-ref name="completeStack"/>
<interceptor-ref name="execAndWait">
<param name="delay">1000</param>
<param name="delaySleepInterval">500</param>
</interceptor-ref>
在你的struts.xml中,即
<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>
我收到一个错误,即
警告:找不到映射到令牌名称令牌的令牌
我不明白,请告诉我为什么会出现此错误以及如何解决它。
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;
}
}
让我知道哪里出错了
谢谢:)
您没有显示 refresh
元标记,但它可能不包含 <s:url>
标记中的 includeParams="all"
,例如
<head>
<title>Please wait</title>
<meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />"/>
</head>
添加
<interceptor-ref name="completeStack"/>
<interceptor-ref name="execAndWait">
<param name="delay">1000</param>
<param name="delaySleepInterval">500</param>
</interceptor-ref>
在你的struts.xml中,即
<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>