struts2 validation_interceptor使用问题
validation_interceptor:register.jsp:<formaction="validate.action"method="post"><input...
validation_interceptor:
register.jsp:
<form action="validate.action" method="post">
<input name="name"/>
<input type="submit" value="提交"/>
</form>
action:
public class ValidateTest {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
System.out.println("abc"+name);
return "success";
}
}
ValidateTest-validation.xml:
<validators>
<field name="name">
<field-validator type="requiredstring">
<message>You must enter a value for bar.</message>
</field-validator>
</field>
</validators>
struts.xml:
<struts>
<package name="mystruts" extends="struts-default" namespace="/">
<action name="validate" class="test.ValidateTest">
<result>index.jsp</result>
<result name="input">register.jsp</result>
</action>
</package>
</struts>
为什么register.jsp文本框不输入任何内容提交后,会转到index.jsp且后台会报:
严重: Validation error for name:You must enter a value for bar.
也就是说ValidateTest-validation.xml执行后,是不满足条件的,可为什么回返回的“success”??? 展开
register.jsp:
<form action="validate.action" method="post">
<input name="name"/>
<input type="submit" value="提交"/>
</form>
action:
public class ValidateTest {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
System.out.println("abc"+name);
return "success";
}
}
ValidateTest-validation.xml:
<validators>
<field name="name">
<field-validator type="requiredstring">
<message>You must enter a value for bar.</message>
</field-validator>
</field>
</validators>
struts.xml:
<struts>
<package name="mystruts" extends="struts-default" namespace="/">
<action name="validate" class="test.ValidateTest">
<result>index.jsp</result>
<result name="input">register.jsp</result>
</action>
</package>
</struts>
为什么register.jsp文本框不输入任何内容提交后,会转到index.jsp且后台会报:
严重: Validation error for name:You must enter a value for bar.
也就是说ValidateTest-validation.xml执行后,是不满足条件的,可为什么回返回的“success”??? 展开
2个回答
展开全部
你的execute方法并没有对要求打印出来的内容作校验,你文本框不输入内容,点提交,调用action,传入一个null,依然满足success,所有跳转的index.jsp,所以表单校验器估计是出了问题,你仔细再看看!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询