日期:2014-05-19  浏览次数:20709 次

Struts2 验证框架的问题
jsp页面 
<form action="userLogin.action" method="post">
<label> 
t工&nbsp;&nbsp;号: 
</label>
<input type="text" name="user.userId" />
<label>
密&nbsp;&nbsp;码:
</label>
<input type="password" name="user.userPassword" />

<input type="submit" class="login-sub" value="" />
<br/>
<b><font color="red"><s:property value="message"/></font></b>
</form>

action类:
private UserBean user;

public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}

验证框架:
<validators>
<!-- 自定义验证器 -->
<field name="user">
<field-validator type="requiredstring">
<message>请输入用户信息</message>
</field-validator>
</field>
</validators>

在验证框架里的name属性怎么写才能才能验证非空???请高手指点


------解决方案--------------------
jsp页面
<form action="userLogin.action" method="post">
<label>
t工&nbsp;&nbsp;号:
</label>
<input type="text" name="user.userId" />
<label>
密&nbsp;&nbsp;码:
</label>
<input type="password" name="user.userPassword" />

<input type="submit" class="login-sub" value="" />
<br/>
<b><font color="red"><s:property value="message"/></font></b>
</form>

action类:
private UserBean user;

public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}

验证框架:
<validators>
<!-- 自定义验证器 -->
<field name="user.userId">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>请输入用户信息</message>
</field-validator>
</field>
</validators>



不知能不能对你有帮助 - -