struts1.2源碼分析記錄

來源:互聯網
上載者:User

標籤:http   java   使用   檔案   資料   io   

struts思路:
1.struts使用的三板斧ActionForm、DispatchAction、ActionMapping
2.主要關注點:Form、Action、Forward
3.頁面如何發送請求參數,後台如何截取.do請求,如何將參數組裝成Form,在Action中如何操作Form,如何尋找目標頁面,如何將Form返回到頁面,頁面如何通過標籤讀取Form屬性

架構主流程:
Struts所有的請求都要走DispatchAction類的public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse res)方法
可以重載execute方法(完成使用者校正,資料庫連接初始化),並可以根據method參數將操作轉向處理方法。

架構細節:
1.接收.do請求
2.將參數轉化成ActionForm
3.找到對應DispatchAction並將ActionForm傳遞給該DispatchAction的對應方法
4.從mapping中找到目標頁面,將ActionForm進行序列化,發送到頁面
5.頁面通過標籤對Form進行解析
架構細節代碼(處理http請求並返回):
1.ActionMapping mapping = processMapping(request, response, path);
2.ActionForm form = processActionForm(request, response, mapping);
3.processPopulate(request, response, form, mapping);
4. ActionForward forward =processActionPerform(request, response,action, form, mapping);
5.processForwardConfig(request, response, forward);
6.response.sendRedirect(response.encodeRedirectURL(uri));
7.RequestDispatcher rd = getServletContext().getRequestDispatcher(uri); rd.forward(request, response);


從設定檔和解析設定檔入手
1.struts-config.xml的結構
a.主要元素:data-sources、form-beans、action-mappings、global-forwards、global-exceptions、message-resources、plug-in
b.通過common-digester工具包結合dtd進行xml的自動解析和載入
2.解析struts-config.xml的過程
a.ModuleConfig是與struts-config.xml配對的java對象
b.將xml配置資訊載入到記憶體後,會將資源分派給各個需要的模組並進行初始化


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.