How to exclude sitemesh filter when resolving error in spring?

I have a Sitemesh filter that will adorn the pages. I configured Spring exceptionResolverso that the whole error goes to a view called error, which then points to WEB-INF/jsp/error.jspthrough InternalResourceViewResolver.

Now the error page is decorated with sitemesh, and I would like to exclude it from the design. Using <exclude>the sitemesh file tag decorator.xmldoes not work. Since the incoming URL can be something ordinary, like /app/login.html, and sitemesh already picks it up and decorates it.

I notice that in Spring, if I have a request @ResponseBodyfor ajax, it will go through the Sitemesh decoration. I wonder how it works? Can I do something errorResolverto bypass sitemesh?

+3
source share
2 answers

This can be done using native exceptionResolver, manual streaming output and return nullModelAndView

public class MyExceptionResolver extends SimpleMappingExceptionResolver{
public ModelAndView resolveException(HttpServletRequest request,
        HttpServletResponse response, Object handler, Exception ex) {

    //other things like logging...
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/error.jsp");
    try {
        dispatcher.forward(request, response);
        response.getOutputStream().flush();
    } catch (ServletException e) {
        log.error(e);
    } catch (IOException e) {
        log.error(e);
    }
    return null;
}
+1
source

At least in SiteMesh 3, this type of exception works (sitemesh3.xml)   

<sitemesh>
  <mime-type>text/html</mime-type>

  <mapping path="/*" decorator="/WEB-INF/sitemesh/decorator.jsp" />
  <mapping path="/app/login.html" exclude="true"/>

</sitemesh>

This has been tested in Spring 3. Hope this helps you.

0
source

All Articles