2011-05-13 87 views
3

我有一個Sitemesh過濾器,將裝飾頁面。我已經配置了一個Spring的exceptionResolver,以便所有的錯誤都會轉到名爲error的視圖,然後這個視圖指向WEB-INF/jsp/error.jspInternalResourceViewResolver如何在春季解決錯誤時排除sitemesh過濾器?

現在錯誤頁面由sitemesh裝飾,我想從裝飾中排除它。使用sitemesh的<exclude>標籤decorator.xml不起作用。因爲傳入的網址可能與/app/login.html一樣正常,sitemesh已經抓住並裝飾它。

我注意到,在春天,如果我有一個@ResponseBody ajax請求,它會通過Sitemesh的裝飾。我想知道它是如何工作的?我可以在errorResolver中繞過sitemesh嗎?

回答

1

它可以通過imlementing自己exceptionResolver,手動流輸出,並返回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; 
} 
0

至少在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> 

完成這在春季3已經嘗試過了,我希望這對你有所幫助。

+0

這是'exclue'而不是'exclude'嗎? – Tor 2015-03-20 09:30:05

+0

原程序員沒有使用拼寫檢查器,現在它使混淆:) – aurelije 2015-04-22 11:39:44

+0

文檔不正確,但是您可以在https://github.com/sitemesh/sitemesh3/blob/master中的架構中看到該屬性被排除/sitemesh/src/main/resources/org/sitemesh/sitemesh3.xsd – 2016-11-15 21:51:30