首页/技术开发/内容

半翻译半整理的一些struts的东东,很浅显的,欢迎指正(4)

技术开发2022-08-05 阅读()
(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 />标签即可。


第1页  第2页  第3页  第4页  第5页 

……

相关阅读