日期:2014-05-17  浏览次数:20788 次

struts2简单的验证框架,帮忙看哪儿错了,验证不出来
NewValidateAction-validation.xml

<validators>
<field name="msg">
<field-validator type="requiredstring">
<message>请输入信息</message>
</field-validator>
</field>
<field name="age">
<field-validator type="int">
<param name="min">13</param>
<param name="max">20</param>
<message>必须在 13至20之间</message>
</field-validator>
</field>
</validators>


NewValidateAction.java:

public class NewValidateAction extends ActionSupport{

private String msg;
private int age;

public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

}

struts.xml配置:

<action name="new_validate" class="com.wjf.action.NewValidateAction">
     <result name ="input">/validate_form.jsp</result>
     <result name ="success">/validate_form.jsp</result>
</action>

jsp页面:


<body>
<s:form action="new_validate">
<s:textfield name="msg" label="姓名" />
<s:textfield name="age" label="年龄" />
<s:submit />
</s:form>

</body>

怎么验证不出来,输入什么都没反映?
------解决方案--------------------
加上提交方式,如下:

<body>
    <s:form action="new_validate" method="post">
        <s:textfield name="msg" label="姓名" />
        <s:textfield name="age" label="年龄" />
        <s:submit />
    </s:form>
 
</body>