JSP <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <s:actionerror/> 回顯錯(cuò)誤信息 <form action="student" method="post" > <s:token></s:token> 加form內(nèi) 姓名:<input type="text" name="student.name"/><br/> 年齡:<input type="text" name="student.age"/><br/> <input type="submit" value="提交"/> </form> </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./dtds/struts-2.0.dtd"> <struts> <package name="manager" extends="struts-default"> <action name="student" class="com.java1234.action.StudentAction" method="add"> <result name="success">/success.jsp</result> 在 struts.xml 里配置,假如出現(xiàn)重復(fù)提交,則直接回到頁(yè)面; <result name="invalid.token">/error.jsp</result> <interceptor-ref name="token"></interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> tokenSesssion 攔截器直接無(wú)視重復(fù)提交的請(qǐng)求; <interceptor-ref name="tokenSession"></interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </action> </package> </struts> ACTION import com.opensymphony.xwork2.ActionSupport; public class StudentAction extends ActionSupport{ private static final long serialVersionUID = 1L; private Student student; public Student getStudent() { return student; } public void setStudent(Student student) { this.student = student; } public String add() throws Exception { System.out.println("開(kāi)始添加學(xué)生:"+student); Thread.sleep(5000); System.out.println(student.getName()+"添加完成"); return SUCCESS; } } |
|
來(lái)自: 擎天豬mpnlajkd > 《Struts》