Java Web project Exception Handling Method (struts2-based project)

Source: Internet
Author: User

1. Access the action that does not exist in the web. The action that struts2 cannot find will execute the following configuration by default. It is best to set "error" to public. Add the following configuration in struts. xml:

<Default-action-ref name = "error"> </default-action-ref> <global-Results> <result name = "error">/error. JSP </result> </Global-Results>

2. When you access the Action Method in the Web, an error is reported, that is, all Exception Handling. To prevent the error information from being displayed on the page, add the following configuration in struts. xml:

<Global-exception-mappings> <exception-mapping result = "error" exception = "Java. Lang. Exception"> </exception-mapping> </Global-exception-mappings>

3. Access JSP that does not exist in the web. This is configured in Web. XML as follows:

<Error-page> <error-code> 404 </error-code> <location>/error. jsp </location> </error-page>

Error-code indicates the error code, and location indicates the redirection to the page. If this configuration is successful, when the server prompts this error code, it will jump to the location page. Location can be an HTML file or a JSP page.

With the above configuration, you can avoid displaying unnecessary error content in front of the user.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.