Handling exceptions in Struts applications

xiaoxiao2021-03-06  90

Struts provides us with two wrong mechanisms, we consistently, what you can think is called his mistake, such as user password errors. The error generated by the location of the location called him anomalies. For the user error handling the Struts framework provides two classes to process it, one is an actionerror (for packaging error message) The other is ActionerrorS (used to store actionerror), 1, create an exception class

(1) Expand the ModuleException class;

(2) Creating a custom anomaly system

2. Capture an exception by JavaWeb container (not all Tomcat support), when developing practical applications, making web containers to capture and business logic related applications are not available, this exception should be processed by Struts, Web Containers are typically responsible for capturing a serious system exception. (EG: 500)

3. Handling an exception configuration in a configuration manner refers to configuring elements in the Struts configuration file, which makes the exception handling class that handles specific exceptions, and request forwarding paths. Configuration methods can avoid processing exceptions by hardcoding in the Action class, thereby improving the flexibility, remaketability, and maintainability of the application.

To customize your own exception handling mechanism, the first step is to inherit the org.apache.struts.Action.ExceptionHandler class. This class has 2 methods to overwrite, one is an excute () another is storeException (). In most cases, only the Excute () method is required.

4. Programming how the exception has been programmed in the Action class to handle exceptions (3, 4 methods combined)

转载请注明原文地址:https://www.9cbs.com/read-105877.html

New Post(0)