In Struts 2:
in case of exception in prepare method, the Action is not called.
How to handle Exception
in prepare()
method so that action method is always called ?
Now I'm doing this but surely exists a better way:
private Exception exceptionInPrepare = null;
@Override
public void prepare() throws Exception {
try {
...
...
} catch (Exception e) {
exceptionInPrepare = e;
}
}
@Action("myMethod")
public String myMethod() {
try {
if (exceptionInPrepare != null) {
throw exceptionInPrepare;
}
...
...
} catch (Exception e) {
...
...
} finally {
...
...
}
return ....
}