Forcefully added some errors to simulate to display errors on login.jsp.
login.jsp is shown back without any errors...
Action Class's execute method:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("In execute() of LoginAction1"); ActionErrors errors = new ActionErrors(); System.out.println("In execute() of LoginAction2"); ActionForward forward = new ActionForward(); System.out.println(" In execute() of LoginAction3"); LoginForm loginForm = (LoginForm) form;
ActionMessages messages = new ActionMessages(); ActionMessage msg; msg = new ActionMessage("error.userid.required");//, "Hellolll"); messages.add("msg1", msg); saveMessages(request, messages); //request.setAttribute("loginForm", loginForm);
try {
// do something here
} catch (Exception e) {
// Report the error using the appropriate name and ID. errors.add("name", new ActionError("id"));
}
// Forcing it to have some errors.... errors.add(ActionErrors.GLOBAL_ERROR,new ActionError(ActionErrors.GLOBAL_ERROR, "Helloooo" )); errors.add("password", new ActionError("error.password.required")); // errors.add("password", new ActionError("error.password.required")); // If a message is required, save the specified key(s) // into the request for use by the <struts:errors> tag.
if (!errors.empty()) { System.out.println("Errors exist. Forward to failure page."); saveErrors(request, errors); //request.g forward = mapping.findForward("failure"); } // Write logic determining how the user should be forwarded. else forward = mapping.findForward("success"); //forward = mapping.findForward("failure");