I have this situation,
in my controller layer, they may throw exceptions, and I want to handle them in one place, for example, I want to log the exception details and forward the request to a jsp page to display some info to our clients.
is there any ways to satisfy my request?
pls be kindly reply this top in English or Chinese~thanks
So if you only need to logging the error and return to a generic page, you can use the error-page into your web.xml and create a simple interceptor to generate your log. See bellow.
[code]@Intercepts @RequestScoped
public class MyLoggingInterceptor implements Interceptor {
@Override
public boolean accepts(ResourceMethod method) {
return true; // intercept all requests
}
@Override
public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance)
throws InterceptionException {
try {
stack.next(method, resourceInstance);
} catch (Exception e) {
// my log code
// you can only print the log message or send by email, etc
}
}