【问题标题】:How to exclude sitemesh filter when resolving error in spring?春季解决错误时如何排除sitemesh过滤器?
【发布时间】:2011-08-24 20:07:38
【问题描述】:

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

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

我注意到,在 Spring 中,如果我有一个用于 ajax 请求的 @ResponseBody,它将绕过 Sitemesh 的装饰。我想知道它是如何工作的?我可以在errorResolver 中做点什么来绕过站点网格吗?

【问题讨论】:

    标签: servlets spring-mvc sitemesh


    【解决方案1】:

    可以实现自己的exceptionResolver,手动流式输出,返回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;
    }
    

    【讨论】:

      【解决方案2】:

      至少在 SiteMesh 3 这种类型的排除工作(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>
      

      这是在 Spring 3 中尝试的。希望对您有所帮助。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 2016-05-30
      • 2017-04-04
      • 1970-01-01
      • 2018-10-10
      相关资源
      最近更新 更多