0

Consider a project with lots of annotated actions.

public class TransferMoney(){

    @Action("transfer-money-show-form")
    public String showForm();

    @Action("transfer-money-confirm")
    public String confirmForm();

    @Action("transfer-money-result")
    public String result();
}

I want to add exception-mapping to confirmForm so I can do it as:

@Action(value = "transfer-money-confirm", 
        exceptionMappings = 
                 {@ExceptionMapping(
                       exception = "java.lang.Exception", 
                        result = "exception")
                  }
        )

However is it a better way ?! As I said I have lots of actions and I don't want to add exceptionMapping for each of them one by one. The action name which I want to add mapping to them all ends with confirm but it seems not useful because the Exception Mapping does not accept regex.

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173

1 Answers1

1

You can use <global-exception-mappings> in struts.xml. Global exception mappings are per S2 package, so you can define different mappings for actions by putting them into separate packages.

<package name="default">
    ...
    <global-exception-mappings>
        <exception-mapping exception="java.lang.Exception" result="exception"/>
    </global-exception-mappings>
    ...
</package>
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143