I asked a question along similar lines yesterday as well. In that question I was suggested to have a global filter (which I already had).
So I have a JSP like below
....code...code
..tags...html...code
Object [] res = iBatisDAO.getReport_pging(null,null,0,null); //call to DB
...more code...
...tags...end
In the above code I am intentionally passing null's because I want it to fail and when it fails I want it to go to our centralized 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>
the 'control' comes to the above JSP via a global filter that I have. it has chain.doFilter()
wrapped in try/catch
block. When exception
happens it redirects to Error.jsp.
When the error happens...it is not being caught by the centralized error page and neither is it caught by the filter. I think filter is not catching it because when filter 'calls' the jsp...there IS no error yet.
I know call to DB is BAD inside a JSP but I am dealing with lot of legacy code.
What can I do to have errors go to centralized error page in this scenario? Also, the JSP does not have the error page imported. I would not want the option of importing an error page to all JSP's I want to have a more general solution.