使用不同的視圖解析器我嘗試解決以下問題:根據要求
我已經建立了我自己的ViewResolver,添加頁眉和頁腳到我的所有請求(感謝,計算器; P)。這工作正常。
問題是,我的ajax-requests,返回一個視圖到一個特定的容器,也自動獲取頁眉和頁腳,當然是不打算。
如果請求包含'/ ajax /',如何讓viewResolver採取不同的行爲?實際上,jstl-Viewer對他們來說工作得很好,但目前,我自己的解析器是唯一使用的解析器,因爲我不知道如何告訴spring在'/ ajax /'上採取不同的行爲。
這裏我自己的解析器,非常簡單,只需從這裏取:
public class ViewTemplate extends InternalResourceView {
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
String dispatcherPath = prepareForRendering(request, response);
request.setAttribute("partial", dispatcherPath.substring(nthOccurrence(dispatcherPath, '/' , 2) + 1));
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/layout.jsp");
rd.include(request, response);
}
// more functions like nthOccurrence
}
我必須告訴這個解析器,如果的indexOf( 「/ AJAX /」)= -1 jstView需要被調用! ?如果是,如何? 還是我做的完全錯了?我想保留我的頁眉/頁腳,因爲它們適用於所有非Ajax請求!
任何幫助表示讚賞!
謝謝!