在struts里怎样提交表单出错后返回前一页面

来源:百度知道 编辑:UC知道 时间:2024/05/21 08:50:35
用myeclipse编写,最好详细点,会加分谢谢

创建一个form 比如叫XxxForm,继承自ActionForm,然后在下面方法里面写
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors = new ActionErrors();
if(表单验证失败){
ActionError error= new ActionError("wrong!");
errors.add("1",error);
}
return errors;
}然后在struts-config.xml中添加:
<form-beans >
<form-bean name="xxxForm" type="XxxForm的类路径" />
</form-beans>

<action
attribute="xxxForm"
input="/当前页面.jsp" <!-- input的页面就是在表单验证失败的情况下(即form的validate方法返回一个非空ActionErrors值时)默认返回的页面。
name="xxxForm"
path="当前页面的action路径"
type="处理此请求的Action路径">
<forward name="success" path="/转向页面.jsp" />
</action&g