我的ActionForm中的validate方法为如下:
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors=new ActionErrors();
if((userName==null)||(userName=="")||(userName.length()==0)){
errors.add("userName",new ActionMessage("userInfo.userNameEmpty"));
}
if((userPassword==null)||(userPassword=="")||(userPassword.length()==0)){
errors.add("userPassword",new ActionMessage("userInfo.userPasswordEmpty"));
}
return errors;
}
资源文件配置如下:
# Resources for parameter 'cn.edu.zjut.struts.ApplicationResources'
# Project LMS
userInfo.userNameEmpty=please input userName!
userInfo.userPasswordEmpty=please input userPassword! 输入页面显示错误标签如下:
<td colspan="3" background="images/login_29.png"><html:errors />
</td>
struts-config.xml配置如下:
<form-beans >
<form-bean name="userForm" type="cn.edu.zjut.ActionFrom.userForm" />
</form-beans>
<action
attribute="userForm"
input="/admin/login.jsp"
name="userForm"
path="/userLogin"
scope="request"
type="cn.edu.zjut.Action.UserLoginAction">
<set-property property="cancellable" value="true" />
<forward name="loginSuccess" path="manageIndex" />
<forward name="loginFailure" path="/admin/loginFailure.html" />
</action> 当不输入用户名和密码时,直接回去执行action中execute,而不返回到输入页面显示错误信息,怎么回事?
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors=new ActionErrors();
if((userName==null)||(userName=="")||(userName.length()==0)){
errors.add("userName",new ActionMessage("userInfo.userNameEmpty"));
}
if((userPassword==null)||(userPassword=="")||(userPassword.length()==0)){
errors.add("userPassword",new ActionMessage("userInfo.userPasswordEmpty"));
}
return errors;
}
资源文件配置如下:
# Resources for parameter 'cn.edu.zjut.struts.ApplicationResources'
# Project LMS
userInfo.userNameEmpty=please input userName!
userInfo.userPasswordEmpty=please input userPassword! 输入页面显示错误标签如下:
<td colspan="3" background="images/login_29.png"><html:errors />
</td>
struts-config.xml配置如下:
<form-beans >
<form-bean name="userForm" type="cn.edu.zjut.ActionFrom.userForm" />
</form-beans>
<action
attribute="userForm"
input="/admin/login.jsp"
name="userForm"
path="/userLogin"
scope="request"
type="cn.edu.zjut.Action.UserLoginAction">
<set-property property="cancellable" value="true" />
<forward name="loginSuccess" path="manageIndex" />
<forward name="loginFailure" path="/admin/loginFailure.html" />
</action> 当不输入用户名和密码时,直接回去执行action中execute,而不返回到输入页面显示错误信息,怎么回事?
<form-beans >
<form-bean name="userForm" type="cn.edu.zjut.ActionFrom.userForm" />
</form-beans>
<action
attribute="userForm"
input="/admin/login.jsp"
name="userForm"
path="/userLogin"
scope="request"
validate="true"
type="cn.edu.zjut.Action.UserLoginAction">
<set-property property="cancellable" value="true" />
<forward name="loginSuccess" path="manageIndex" />
<forward name="loginFailure" path="/admin/loginFailure.html" />
</action>
试试看