(10) System exception handling

Source: Internet
Author: User

When the request is sent in the page, the request is processed by the system error, if there is no special processing in the request process of the exception information, then the return to the user is the background exception information page, in order to avoid the error page directly presented to the user, the error can be processed.

Layered exceptions

Background processing in this system is divided into 3 layers, the action, service, and DAO layers, each of which may have a corresponding error.

①action layer may appear parsing request parameters, return the result of a problem;

②service layer may appear in the request to do business operation problems, there is a problem to judge according to the actual situation will affect the results of the operation, the action should be based on the exception information to determine whether the operation is successful;

The ③dao layer may also appear to be an error in manipulating the database, and this type of error is generally fatal and can affect the result of the operation.

In this case, at least two types of exception information are identified in 3 levels.

Make a total system exception class:

Action Layer Exception class:

Service Layer Exception class:

Exception handling Global Exception mapping

Configure a package that includes global exception mappings and global results in the Struts General profile (Struts.xml) and then inherit the Struts profile (*-struts.xml) from all other business modules to handle the specific exceptions thrown by the background and handle them.

In total configuration file Struts.xml:

Inherit the package from the general configuration file in the *-sturts.xml in the Child Business module:

Throw a system exception in the specific background processing code:

If only actionexception is thrown in the action, it can also be captured if the mapping of the Java.lang.Exception exception class is configured in the global exception map if the exception is not present.

Develop return type (Strutsresultsupport)

In the case of special circumstances, if there is no exception information, but there are errors and error messages and so on, you also need to do a friendly error handling, you can use the Strutsresultsupport return result type to achieve specific processing. In this way, you need to inherit strutsresultsupport, and then you can get the information about this request in the subclass, and then process the results according to the relevant information:

Define the global processing type and global processing results in the Struts.xml general configuration file:

(10) System exception handling

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.