[摘要](password.length() == 0) ) errors.add("password",new ActionError("errors.password.re... (password.length() == 0) ) { errors.add("password",new ActionError("errors.password.required")); } return errors; } ………………… }
Action类: public class LoginAction extends Action { …………………… public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponseresponse) throws IOException, ServletException { String user = null; // Default target to success String target = "success"; // Use the LoginForm to get the request parameters String username = ((LoginForm)form).getUsername(); String password = ((LoginForm)form).getPassword(); user = getUser(username, password); // Set the target to failure if ( user == null ) { target = "login"; ActionErrors errors = new ActionErrors(); errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("errors.login.unknown",username)); // Report any errors we have discovered back to the // original form if (!errors.empty()) { saveErrors(request, errors); } } else { HttpSession session = request.getSession(); session.setAttribute("USER", user); } // Forward to the appropriate View return (mapping.findForward(target)); } } 在表现层中表现错误只须要写上<html:error />标签即可。
|
关键词: 半翻译半整理的一些struts的东东 很浅显的 欢迎指正(4)