Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Servlets 在spring中解决错误时如何排除sitemesh筛选器?_Servlets_Spring Mvc_Sitemesh - Fatal编程技术网

Servlets 在spring中解决错误时如何排除sitemesh筛选器?

Servlets 在spring中解决错误时如何排除sitemesh筛选器?,servlets,spring-mvc,sitemesh,Servlets,Spring Mvc,Sitemesh,我有一个Sitemesh过滤器,可以装饰页面。我已经配置了一个Spring的异常解析器,这样所有的错误都会转到一个名为error的视图,然后通过InternalResourceViewResolver指向WEB-INF/jsp/error.jsp 现在,错误页面由sitemesh装饰,我想将其从装饰中排除。使用sitemeshdecorator.xml的标记不起作用。因为传入的url可能与/app/login.html一样正常,而sitemesh已经捕捉到并装饰了它 我注意到,在春季,如果我有一

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

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


我注意到,在春季,如果我有一个用于ajax请求的
@ResponseBody
,它将绕过Sitemesh的装饰。我想知道它是怎么工作的?我是否可以在
错误解析程序
中制作一些东西来绕过sitemesh?

可以通过实现自己的
例外解析程序
,手动流式输出并返回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 3中,这种类型的排除是有效的(sitemesh3.xml)


文本/html

这是在春季3尝试。我希望这对您有所帮助。

为什么它是“exclue”而不是“exclude”?最初的程序员没有使用拼写检查器,现在这让人感到困惑:)文档不正确,但您可以在
<sitemesh>
  <mime-type>text/html</mime-type>

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

</sitemesh>