Servlets 在spring中解决错误时如何排除sitemesh筛选器?
我有一个Sitemesh过滤器,可以装饰页面。我已经配置了一个Spring的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已经捕捉到并装饰了它 我注意到,在春季,如果我有一
异常解析器
,这样所有的错误都会转到一个名为error
的视图,然后通过InternalResourceViewResolver
指向WEB-INF/jsp/error.jsp
现在,错误页面由sitemesh装饰,我想将其从装饰中排除。使用sitemeshdecorator.xml的
标记不起作用。因为传入的url可能与/app/login.html
一样正常,而sitemesh已经捕捉到并装饰了它
我注意到,在春季,如果我有一个用于ajax请求的@ResponseBody
,它将绕过Sitemesh的装饰。我想知道它是怎么工作的?我是否可以在错误解析程序中制作一些东西来绕过sitemesh?可以通过实现自己的例外解析程序,手动流式输出并返回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;
}
至少在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>