3

I have a Sitemesh filter that will decorate pages. I have configured a Spring's exceptionResolver so that all the error will go to a view called error which is then pointed to WEB-INF/jsp/error.jsp through InternalResourceViewResolver.

Now the error page is decorated by sitemesh and I would like to exclude it from decoration. Using <exclude> tag of sitemesh decorator.xml does not work. Because the incoming url may be something as normal as /app/login.html and sitemesh already catch it and decorate it.

I notice that in Spring if I have a @ResponseBody for ajax request, it would by pass Sitemesh's decoration. I wonder how it works? Can I make something in the errorResolver to bypass sitemesh also?

skaffman
  • 398,947
  • 96
  • 818
  • 769
jackysee
  • 2,051
  • 4
  • 32
  • 38

2 Answers2

1

It can be done by imlementing own exceptionResolver, streaming output manually and return null ModelAndView

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;
}
jackysee
  • 2,051
  • 4
  • 32
  • 38
0

At least in SiteMesh 3 this type of exclude 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 is tried in Spring 3. I hope this helped you.

Brian Matthews
  • 8,506
  • 7
  • 46
  • 68
aurelije
  • 768
  • 1
  • 6
  • 14
  • How come it's 'exclue' instead of 'exclude' ? – Thor Mar 20 '15 at 09:30
  • The original programmer didn't used spell checker, and now thet makes confusion :) – aurelije Apr 22 '15 at 11:39
  • The documentation is incorrect but you can see the attribute is exclude in the schema at https://github.com/sitemesh/sitemesh3/blob/master/sitemesh/src/main/resources/org/sitemesh/sitemesh3.xsd – Brian Matthews Nov 15 '16 at 21:51