struts2内置校验器没有响应是怎么回事,写的validation.xml没有起到校验功能
UserAction-validation.xml<?xmlversion="1.0"encoding="gb2312"?><!DOCTYPEvalidatorsPUBL...
UserAction-validation.xml
<?xml version="1.0" encoding="gb2312" ?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="id">
<field-validator type="requiredstring">
<message>密码不能为空!</message>
</field-validator>
</field>
</validators>
UserAction.java
/*包和引入文件*/
public class UserAction extends ActionSupport {
private String name;
private String id;
private String age;
/*set get方法*/
public String addUser()
{
return SUCCESS;
}
public String execute()
{
return SUCCESS;
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2_user" extends="struts-default" namespace="/user">
<action name="addUser" class="act.UserAction" >
<result name="input">/excep.jsp</result>
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
excep.jsp
/*head*/
<body>
This is my JSP page. <br>
<s:form action="addUser" namespace="/user">
<s:textfield name="id" label="用户id" cssStyle="width:100"></s:textfield>
<s:textfield name="name" label="用户名称" cssStyle="width:100"></s:textfield>
<s:textfield name="age" label="用户年龄" cssStyle="width:100"></s:textfield>
<s:submit value="注册"></s:submit>
</s:form>
</body>
</html> 展开
<?xml version="1.0" encoding="gb2312" ?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="id">
<field-validator type="requiredstring">
<message>密码不能为空!</message>
</field-validator>
</field>
</validators>
UserAction.java
/*包和引入文件*/
public class UserAction extends ActionSupport {
private String name;
private String id;
private String age;
/*set get方法*/
public String addUser()
{
return SUCCESS;
}
public String execute()
{
return SUCCESS;
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2_user" extends="struts-default" namespace="/user">
<action name="addUser" class="act.UserAction" >
<result name="input">/excep.jsp</result>
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
excep.jsp
/*head*/
<body>
This is my JSP page. <br>
<s:form action="addUser" namespace="/user">
<s:textfield name="id" label="用户id" cssStyle="width:100"></s:textfield>
<s:textfield name="name" label="用户名称" cssStyle="width:100"></s:textfield>
<s:textfield name="age" label="用户年龄" cssStyle="width:100"></s:textfield>
<s:submit value="注册"></s:submit>
</s:form>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询