struts2 基于xml校验问题、、求高手看下
package com.struts.user;
public class User {
private String userName;
private String passWord;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
-------------------------
package com.struts2.action;
import com.opensymphony.xwork2.ActionSupport;
import com.struts.user.User;
public class Login extends ActionSupport {
User user;
String result="fail";
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("dddddddddddddddddddddddddd");
if(user.getUserName().equals("java"))
{
System.out.println("dddddddddddddddddddddddddd");
result="success";
}
return result;
}
}
---------------------------------------------
xml校验文件Login-validation.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<validators>
<field name="user.userName">
<!-- 验证字符串不能为空 -->
<field-validator type="requiredstring">
<!-- 去空格 -->
<param name="trim">true</param>
<!-- 错误提示信息 -->
<message>用户名不能为空</message>
</field-validator>
<!-- 验证字符串长度 -->
<field-validator type="stringlength">
<param name="minLength">2</param>
<param name="maxLength">20</param>
<message>用户名长度应在2到18个字符间</message>
</field-validator>
</field>
<field name="user.password">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>密码不能为空</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">6</param>
<param name="maxLength">18</param>
<message>密码长度应在6到18个字符之间</message>
</field-validator>
</field>
</validators>
------------------------------------------------------
struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="Login" extends="struts-default" >
<action name="login" class="