<html:errors> struts tutorial or example

后端 未结 3 1639
终归单人心
终归单人心 2021-02-09 05:31

I\'m trying to make a login page in Struts. The idea is to validate if the user exists, etc, and then if there is an error, return to the login page with the errors in red (the

3条回答
  •  我在风中等你
    2021-02-09 06:26

    Here's one: //struts.apache.org/1.3.5/struts-taglib/apidocs/org/apache/struts/taglib/html/package-summary.html#package_description

    Here I'm assuming Struts 1. I don't know if it has changed for Struts 2.

    You can put an errors.header and errors.footer into your message resources file:

    errors.header=

    Errors:

      errors.footer=

    The header and footer are displayed only if the ActionErrors object has any errors in it.

    In your Action class, do this:

    ActionErrors errors = new ActionErrors();
    if (badInput) {
      errors.add(ActionErrors.GLOBAL_ERROR,
        new ActionError("error.bad.input", badString);    // key in messages resource file
                                        // badString will replace {0} in message
    }
    

    Then before returning:

    saveErrors(request, errors);
    

    In your messages resource file:

    error.bad.input=
  • Bad input: '{0}' is invalid.
  • Now when the tag is processed, it will turn into:

    Errors:

    • Bad input: 'xxyyzzz' is invalid.

提交回复
热议问题