1. 程式人生 > >struts標籤返回登陸錯誤資訊

struts標籤返回登陸錯誤資訊

1 接收action中返回的錯誤

LoginAcrion.java

if(!user.getUserPassword().equals(UserPassword)){
   ActionMessages errors=new ActionMessages();
   errors.add("userpassword",new ActionMessage

("com.login.UserPassword"));
   saveMessages(request,errors);
   return (new ActionForward(mapping.getInput()));
      
  }


Login.jsp

<logic:present name="userInfor" scope="session">
 <bean:message key="hello.jsp.page.hello"/>
 <bean:write name="userInfor" property="userName"></bean:write>!<br>
</logic:present>

接收並顯示錯誤

2 接收LoginForm中的validate()的錯誤


LoginForm.java

public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
  ActionErrors errors=new ActionErrors();
  if(null==cardID || cardID.length()<1){
   errors.add("username",new ActionMessage("com.login.CardID"));
  }
  if(null==userPassword || userPassword.length()<1){
   errors.add("username",new ActionMessage("com.login.UserPassword"));
  }
  return errors;
 }

Login.jsp

<html:errors/>

接收並顯示錯誤