下面是java代码:
import com.opensymphony.xwork2.ActionSupport;
public class Test extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 8650051575559688141L;
private String message;
public String execute(){
System.out.println(message);
return SUCCESS;
}
public String save(){
return "ok";
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
struts.xml文件代码:
<!-- action 设置-->
<package name="test" extends="struts-default" namespace="/testToken">
<action name="test" class="com.test.Test">
<result name="invalid.token">/error.jsp</result> <!--当重复提交时,转到error.jsp页面-->
<result>/test.jsp</result>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="token" />
</action>
</package>
</struts>
test.jsp代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>struts2 test token</title>
<s:head />
</head>
<body>
<s:actionerror/>
<s:form action="test" namespace="/testToken">
<s:textfield name="message" label="请输入您的信息"/>
<s:token name="token"/>
<s:submit value="确定" />
</s:form>
</body>
</html>
error.jsp代码