1.在ActionForm中添加
Public ActionErrors validate(ActionMapping arg0,HttpServletRequest arg1)
{
ActionErrors errors=new ActionErrors();
arg1.setAttribute("loginFormBean",this);
if(username==null||username.equals(""))
{
errors.add("username",new ActionMessage("login.error.username"));
}
if(password==null||password.equals(""))
{
errors.add("password",new ActionMessage("login.error.password"));
}
return errors;
}
2.在jsp中添加
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<tr>
<td>用户名</td>
<td>
<logic:present name="loginFormBean">
<html:text property="username" name="loginFormBean"/>
</logic:present>
<logic:notPresent name="loginFormBean">
<input type="text" name="username">
</logic:notPresent>
<html:errors property="username"/>
</td>
</tr>
<tr>
<td>密 码</td>
<td>
<logic:present name="loginFormBean">
<html:text property="password" name="loginFormBean"/>
</logic:present>
<logic:notPresent name="loginFormBean">
<input type="text" name="password">
</logic:notPresent >
<html:errors property="password"/>
</td>
</tr>