Adding Global and Local Exceptions to a Struts Configuration
Struts allows exception handlers to be added to a Struts configuration in order to process application exceptions as they occur at runtime. Exceptions can be added to the global Struts configuration or locally to an action element within the Struts configuration.
Inserting an exception using the Struts configuration form editor
-
Open a Struts Configuration file using the Project Explorer.
-
In the Struts Config view, you will see the list of Struts artifacts including the current list of Global Exceptions. You can expand this list by clicking the plus sign (+) if it is collapsed.
-
Right-click the Global Exception node and select New Exception.
-
Enter exception properties and the exception paths through the resulting Exception Tag dialog.
-
Click OK to insert the exception into the opened Struts configuration file. The new exception will appear under the list of Global Exceptions and can be modified by selecting the specific exception and updating the exception properties.
Note: Using this technique will insert a global exception by default. A local exception will only be inserted by right-clicking an action under the list of Action Mappings and selecting New Exception.
Inserting an exception from the Struts outline view
-
To insert a global exception from the Struts outline view
-
Expand the Global Exceptions node under the Outline view.
-
Right-click and select New Exception from the pop-up menu on the Outline view
-
Enter exception properties through the resulting Exception Tag dialog.
-
Click OK.
-
To insert a local exception from the Struts outline view
-
Expand the Action Mappings node under the Struts Outline view.
-
Select a Struts Action in the Outline view. The action will simultaneously be selected in the Source pane of the Struts Configuration Editor. This action will also become the container for the newly inserted exception.
-
Right-click and select New Exception from the pop-up menu on the Outline view. Note: The Outline view allows you to open the pop-up menu and select the action at the same time.
-
Enter exception properties through the resulting Exception Tag dialog.
-
Click Ok.
Inserting an exception from the Struts navigation editor
-
To insert a local exception from the Navigation tab
-
Expand the Action Mappings node under the Struts Outline view.
-
Double-click a Struts Action in the Outline view. The action will simultaneously be selected in the Source pane of the Struts Configuration Editor and opened in the Navigation tab.
-
Select the action in the Navigation pane. The action will appear with a highlighted outline when it is selected.
-
Right-click and select New Exception from the pop-up menu on the selected action.
-
Enter exception properties through the resulting Exception Tag dialog.
-
Click Ok.
Still need help? Post a question on the Workshop
newsgroup.