Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to handle this is to create another handler implementing the <em><a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/servlet/HandlerExceptionResolver.html" rel="noreferrer">org.springframework.web.servlet.HandlerExceptionResolver</a></em> and <em><a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/core/Ordered.html" rel="noreferrer">org.springframework.core.Ordered</a></em> -interfaces. In your own implementation, you do something like the following:</p> <pre><code>public class AccessDeniedExceptionResolver implements HandlerExceptionResolver, Ordered { private int order; @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) { if(exception instanceof AccessDeniedException) { return new ModelAndView("redirect:/login"); //Replace with redirect to your login-page } return null; //Null-return = pass the exception to next handler in order } public void setOrder(int order) { this.order = order; } @Override public int getOrder() { return order; } } </code></pre> <p>Now, the Ordered-interface implementation allows you to tell the order the exception handlers are invoked in. The <em>SimpleMappingExceptionResolver</em> implements the Ordered interface also, so you could do something like following in your bean-definitions:</p> <pre><code>&lt;bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"&gt; &lt;property name="exceptionMappings"&gt; &lt;props&gt; &lt;prop key="java.lang.RuntimeException"&gt;common/error&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="order" value="1"/&gt; &lt;/bean&gt; &lt;bean class="package.to.your.handler.AccessDeniedExceptionResolver"&gt; &lt;property name="order" value="0"/&gt; &lt;/bean&gt; </code></pre> <p>The bean with the LOWER order-value has HIGHER priority (meaning it will be invoked BEFORE the ones with larger values, in this case AccessDeniedExceptionResolver is invoked before SimpleMappingExceptionResolver.</p> <p>Hope this helped.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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