急求:struts2 中validation.xml验证文件为什么没有用?
1.目录格式如下src/wty/Login.java..Login-validation.xmlwebroot/jsp/login.jsploginSuccess.jsp...
1.目录格式如下
src/wty/Login.java
..Login-validation.xml
webroot/jsp/login.jsp
loginSuccess.jsp
2.首先请求login.jsp,内容是:
<s:form action="loginConfirm.action" method="post">
<s:fielderror name="name"></s:fielderror>
<s:textfield name="name" label="用户名"></s:textfield>
<s:fielderror name="password"></s:fielderror>
<s:password name="password" label="密码"></s:password>
<s:submit value="登陆"></s:submit>
</s:form>
3.strust2注入Login,其中2个属性和一个loginConfirm方法{
String name;
String password;
loginConfirm(){
return "success";
}
}
3.Login-validation.xml中内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "validators1.0.2" "xwork-validator-1.0.2.dtd" >
<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>用户名不能为空</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>密码不能为空</message>
</field-validator>
</field>
</validators>
4.struts.xml
<package name="hello" extends="struts-default" namespace="/">
</action>
<action name="loginConfirm" class="wty.Login" method="loginConfirm">
<result name="success">/jsp/loginSuccess.jsp</result>
<result name="input">/jsp/login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
</package> 展开
src/wty/Login.java
..Login-validation.xml
webroot/jsp/login.jsp
loginSuccess.jsp
2.首先请求login.jsp,内容是:
<s:form action="loginConfirm.action" method="post">
<s:fielderror name="name"></s:fielderror>
<s:textfield name="name" label="用户名"></s:textfield>
<s:fielderror name="password"></s:fielderror>
<s:password name="password" label="密码"></s:password>
<s:submit value="登陆"></s:submit>
</s:form>
3.strust2注入Login,其中2个属性和一个loginConfirm方法{
String name;
String password;
loginConfirm(){
return "success";
}
}
3.Login-validation.xml中内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "validators1.0.2" "xwork-validator-1.0.2.dtd" >
<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>用户名不能为空</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>密码不能为空</message>
</field-validator>
</field>
</validators>
4.struts.xml
<package name="hello" extends="struts-default" namespace="/">
</action>
<action name="loginConfirm" class="wty.Login" method="loginConfirm">
<result name="success">/jsp/loginSuccess.jsp</result>
<result name="input">/jsp/login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
</package> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询