本文介绍了春季解决错误时如何排除Sitemesh过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个Sitemesh过滤器,用于装饰页面.我已经配置了Spring的exceptionResolver,以便所有错误都将转到一个名为error的视图,然后该视图通过InternalResourceViewResolver指向WEB-INF/jsp/error.jsp.

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.

现在,错误页面由sitemesh装饰,我希望将其从装饰中排除.使用sitemesh decorator.xml<exclude>标记不起作用.因为传入的url可能与/app/login.html一样正常,并且sitemesh已经捕获并装饰了它.

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.

我注意到在Spring中,如果我有一个@ResponseBody用于ajax请求,它将通过Sitemesh的修饰.我想知道它是如何工作的?我可以在errorResolver中制作一些内容来绕过sitemesh吗?

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?

推荐答案

可以通过实施自己的exceptionResolver,手动流输出并返回null ModelAndView

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

这篇关于春季解决错误时如何排除Sitemesh过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:41