<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    StevenBot-Saltsam

    眼睛能裝下世界,為何卻裝不下眼淚? 一只風箏一輩子只為一根線冒險。 那不是一場游戲,為何總有一根線牽著心懷,隱隱作疼? 那不是一段邂逅,為何飄在橋上的影子,總纏進夢鄉? 那不是一個夢境,為何你的溫柔私語,總是不經意的響起?

    導航

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    統計

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    datas link

    OSChinal Sources codes Library

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    SpringMVC web框架學習 Controller 分析

    SpringMVC web框架學習 Controller 分析

    org.springframework.web.servlet.mvc.AbstractController (implements org.springframework.web.servlet.mvc.Controller)

    Spring MVC框架中的Controller對請求進行處理:所有的Controller都實現接口Controller:

    public interface Controller {       /**      * Process the request and return a ModelAndView object which the DispatcherServlet      * will render. A <code>null</code> return value is not an error: It indicates that      * this object completed request processing itself, thus there is no ModelAndView      * to render.      * @param request current HTTP request      * @param response current HTTP response      * @return a ModelAndView to render, or <code>null</code> if handled directly      * @throws Exception in case of errors      */     ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception;   } 上面的doc表明Controller返回的modelandview可以使空,表明請求都是該函數中處理完成了,不需要modeland來進行渲染。
     
    在繼續之前先介紹一個有用的工具類:WebUtils。用這個可以簡化session,request的處理。具體的內容可以參考文檔。
     
    Controller的第一個實現是:AbstractController。他是一個Abstract類,除了實現了Controller接口,它還繼承了WebContentGenerator。
     
    WebContentGenerator的作用是什么?參考文檔可以發現,該類主要對Cache和Session進行管理。
     
    cacheSeconds 指定內容緩存的時間,默認為1
    requireSession 是否需要會話,默認支持
    supportedMethods 支持的方法,默認是GET\post\Head
    useCacheControlHeader 指定是否使用http1.1的cache控制頭信息,默認使用
    useCacheControlNoStore 指定是否設置http1.1的cache控制頭信息為no-store。默認使用
    useExpiresHeader 指定是否使用http1.0的expire頭信息。默認使用
    用戶可以對這些參數進行測試,cache和expire信息涉及到了http協議信息,更多信息可以參考http協議文檔。這里不再說明。
     
    再看AbstractController的代碼:
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    // Delegate to WebContentGenerator for checking and preparing.
    checkAndPrepare(request, response, this instanceof LastModified);

    // Execute handleRequestInternal in synchronized block if required.
    if (this.synchronizeOnSession) {
    HttpSession session = request.getSession(false);
    if (session != null) {
    Object mutex = WebUtils.getSessionMutex(session);
    synchronized (mutex) {
    return handleRequestInternal(request, response);
    }
    }
    }
    return handleRequestInternal(request, response);
    }
    checkandPrepare的目的就是使用用于進行的配置來對request進行預處理和準備。
    他會檢查支持的方法,和會話,然后應用cache設置。
    如果需要session同步,就進行同步處理。session同步應用于有session的情況下。如果沒有session,session同步是沒有用的。
    AbstractController會調用handleRequestInternal方法進行處理,繼承AbstractController的類需要實現該方法。
    下面我們再看看AbstractUrlViewController 的代碼實現和文檔,先看handleRequestInternal的實現:

     
    /**
    * Retrieves the URL path to use for lookup and delegates to
    * {@link #getViewNameForRequest}.
    */
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    String lookupPath = getUrlPathHelper().getLookupPathForRequest(request);
    String viewName = getViewNameForRequest(request);
    if (logger.isDebugEnabled()) {
    logger.debug("Returning view name '" + viewName + "' for lookup path [" + lookupPath + "]");
    }
    return new ModelAndView(viewName);
    }
    可以看到,它使用了getViewNameForRequest獲取需要的viewName。而getViewNameForRequest是一個抽象函數,需要子類實現。lookupPath就是我們請求的URL中的一部分。如我們使用UrlFilenameViewController來進行如下的配置:
    <bean name="/index.do" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"></bean>、
    09-11-25 11:56:06 - DEBUG [http-8200-1] - Returning view name 'index' for lookup path [/index.do]
    該Controller對/index.do解析成index,然后再通過viewResolver對index進行擴展為/jsp/index.jsp。從而找到該頁面。
    可以看到這個類的主要是用于對url進行解析,然后轉到合適的頁面上,而在轉到這個頁面之前不需要進行特別的處理。
    明白了該類的作用自然也就知道了UrlFilenameViewController的作用。這里不再進行詳細分析。

    posted on 2011-10-15 09:49 Steven_bot 閱讀(722) 評論(0)  編輯  收藏 所屬分類: spring

    主站蜘蛛池模板: 国产日产亚洲系列最新| 免费一级毛片不卡在线播放| 亚洲男人的天堂www| 瑟瑟网站免费网站入口| 免费看男女下面日出水视频| 久久久久久免费视频| 亚洲丁香色婷婷综合欲色啪| 免费看成人AA片无码视频吃奶| 亚洲毛片αv无线播放一区| 四虎影视无码永久免费| 亚洲精品夜夜夜妓女网| 免费国产午夜高清在线视频| 亚洲日本中文字幕区| 亚洲国产精品免费在线观看| 亚洲综合无码一区二区三区| 6080午夜一级毛片免费看6080夜福利 | 免费无遮挡无遮羞在线看| 免费在线观看黄网站| aa午夜免费剧场| 九月丁香婷婷亚洲综合色| 午夜不卡久久精品无码免费 | 美女视频黄a视频全免费| 亚洲av无码不卡久久| 日韩免费三级电影| 特级毛片免费观看视频| 中文字幕第一页亚洲| 久久久久久久岛国免费播放| 亚洲手机中文字幕| 国产精品免费小视频| 久久高潮一级毛片免费| 久久亚洲精品中文字幕| 成人免费无码大片a毛片| 一个人看的免费视频www在线高清动漫 | 亚洲Aⅴ无码专区在线观看q| av大片在线无码免费| 美女扒开屁股让男人桶爽免费| 亚洲综合国产一区二区三区| 一级女人18毛片免费| 黄色免费网址在线观看| 久久精品九九亚洲精品| 国产aa免费视频|