标签:
<s:debug></s:debug>
<s:form action="TokenAction" method="post">
<s:textfield name="username" label="username"></s:textfield>
<s:submit label="提交"></s:submit>
<s:token />
</s:form>
|
package cn.edu.shu.second.form.token;
import com.opensymphony.xwork2.ActionSupport;
public class TokenAction extends ActionSupport {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String execute() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("休息了一秒咯");
return "success";
}
}
|
<action name="TokenAction" class="cn.edu.shu.second.form.token.TokenAction">
<interceptor-ref name="token" />
<interceptor-ref name="defaultStack" />
<result name="invalid.token">error.jsp</result>
<result name="success">success.jsp</result>
</action>
|
Extending the interceptor: While not very common for users to extend, this interceptor is extended by the Example code: <action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="token"/> <interceptor-ref name="basicStack"/> <result name="success">good_result.ftl</result> </action> <-- In this case, myMethod of the action class will not get checked for invalidity of token --> <action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="token"> <param name="excludeMethods">myMethod</param> </interceptor-ref name="token"/> <interceptor-ref name="basicStack"/> <result name="success">good_result.ftl</result> </action> |
Struts2.3.20使用token防表单重复提交:警告: Could not find token name in params.
标签:
原文地址:http://blog.csdn.net/shijiebei2009/article/details/42677737