开发者

How to exclude sitemesh filter when resolving error in spring?

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 inc开发者_StackOverflow中文版oming 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?


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜