I asked a question similar lines yesterday. In this question, I was offered to have a global filter (which I already had).
So I have a JSP as shown below
....code...code ..tags...html...code Object [] res = iBatisDAO.getReport_pging(null,null,0,null);
In the code above, I intentionally pass null because I want it to fail, and when it doesn't work, I want it to go to our central error page. I have the following in my web.xml
<error-page> <exception-type>com.ibatis.common.jdbc.exception.NestedSQLException</exception-type> <location>/errorpages/Error.jsp</location> </error-page> <error-page> <exception-type>org.springframework.dao.DataAccessException</exception-type> <location>/errorpages/Error.jsp</location> </error-page> <error-page> <exception-type>javax.servlet.ServletException</exception-type> <location>/errorpages/Error.jsp</location> </error-page> <error-page> <exception-type>java.sql.SQLException</exception-type> <location>/errorpages/Error.jsp</location> </error-page> <error-page> <exception-type>org.springframework.jdbc.UncategorizedSQLException</exception-type> <location>/errorpages/Error.jsp</location> </error-page>
"control" comes to the above JSP through the global filter that I have. it has chain.doFilter() wrapped in a try/catch . When exception occurs, it is redirected to Error.jsp.
If an error occurs ... it does not get on the centralized error page and does not get into the filter. I think the filter did not catch it, because when the filter "calls" jsp ... there is no error yet.
I know that a DB call is a BAD inside the JSP, but I am dealing with a lot of legacy code.
What can I do to get errors on the centralized error page in this scenario? In addition, the JSP does not import the imported error page. I would not want to import an error page for all JSPs. I want to have a more general solution.
drake source share