Results 1 to 2 of 2
  1. #1
    sandor is offline Member
    Join Date
    Apr 2007
    Rep Power

    Default error message on jsp

    Am trying to learn struts...not easy.
    Anyway, I want to display an error message on a page if the user forgets to enter a field. I figured out how to do that with the validate() method in the ActionForm. OK, but now I want to make the error show up if they did something the database does not like. So I am off into the Action now.
    Lets say they want to order some widgets, and there were some in the inventory when the screen came up, but they looked at it a while, they went and had a cup of coffee, and when they got back and clicked the "order" button the application goes out to the database and lo and behold, there are no more widgets left. So how do I deal with this and show that nice little error message on the same screen. "sorry, the last widget has been sold".

  2. #2
    pegitha is offline Member
    Join Date
    Apr 2007
    Rep Power


    Here is how I normally handle something like this:
    Java Code:
    public ActionForward getWidgets(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                HttpServletResponse response) throws Exception
            ActionMessages errors = new ActionMessages();
            ActionForward forward = new ActionForward();
                List widgets=WidgetManager.getWidgets();
                forward = mapping.findForward("gotthem");
            catch (NoWidgetsFoundException e)
                errors.add("noWidgetsLeftError", new   ActionMessage("error.noWidgetsLeftError"));
                saveErrors(request, errors);
            return (forward);
    My WidgetManager.getWidgets() throws a NoWidgetsFoundException. That is caught in the Action and then you create a new ActionMessage. The message that is going to be displayed is still in the file, just like the errors you collect in the Form.validate() method.

Similar Threads

  1. Please wail Message in jsp
    By in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-02-2008, 12:29 PM
  2. java error message
    By baileyr in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 03:47 AM
  3. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 06:19 PM
  4. Replies: 7
    Last Post: 08-12-2007, 03:47 PM
  5. About bean:message
    By yuchuang in forum Web Frameworks
    Replies: 1
    Last Post: 05-03-2007, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts