Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to catch and throw errors in JSP
    text
    copied!<p>I asked a <a href="https://stackoverflow.com/questions/2410808/how-do-i-catch-errors-globally-log-them-and-show-user-an-error-page-in-j2ee-app">question</a> along similar lines yesterday as well. In that question I was suggested to have a global filter (which I already had).</p> <p>So I have a JSP like below</p> <pre><code>....code...code ..tags...html...code Object [] res = iBatisDAO.getReport_pging(null,null,0,null); //call to DB ...more code... ...tags...end </code></pre> <p>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</p> <pre><code> &lt;error-page&gt; &lt;exception-type&gt;com.ibatis.common.jdbc.exception.NestedSQLException&lt;/exception-type&gt; &lt;location&gt;/errorpages/Error.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;exception-type&gt;org.springframework.dao.DataAccessException&lt;/exception-type&gt; &lt;location&gt;/errorpages/Error.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;exception-type&gt;javax.servlet.ServletException&lt;/exception-type&gt; &lt;location&gt;/errorpages/Error.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;exception-type&gt;java.sql.SQLException&lt;/exception-type&gt; &lt;location&gt;/errorpages/Error.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;exception-type&gt;org.springframework.jdbc.UncategorizedSQLException&lt;/exception-type&gt; &lt;location&gt;/errorpages/Error.jsp&lt;/location&gt; &lt;/error-page&gt; </code></pre> <p>the 'control' comes to the above JSP via a global filter that I have. it has <code>chain.doFilter()</code> wrapped in <code>try/catch</code> block. When <code>exception</code> happens it redirects to Error.jsp.</p> <p>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. </p> <p>I know call to DB is BAD inside a JSP but I am dealing with lot of legacy code. </p> <p>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. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload