Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學;靜其心,可悟天下之理;恒其心,可成天下之業。

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
           

          用戶在地址欄鍵入http://localhost:8080/后,整個Liferay系統發生了些什么呢?

          1. 第一步,生成 http://localhost:8080/c
          Request:   GET/HTTP/1.1
          Response: 
          狀態:HTTP/1.1 200 OK
          內容:... <body onload="javascript:location.replace('/c')"> ...

          解釋:
          在web.xml中有關于首頁的定義如下,也就是說當用戶敲入http://localhost:8080/所調用的頁面。

          web.xml
          --------
          <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>index.jsp</welcome-file>
          </welcome-file-list>

          在index.jsp中有如下內容,所以可以知道Response的內容如何得來。

          index.jsp
          ----------
          <%@ page import="com.liferay.portal.util.PortalUtil" %>
          <html>
          <head>
            <title></title>
            <meta content="0; url=<%= PortalUtil.getPathMain() %>" http-equiv="refresh">
          </head>
          <body onload="javascript:location.replace('<%= PortalUtil.getPathMain() %>')">
          </body>
          </html>


          2. 第二步,生成 http://localhost:8080/c/portal/layout

          Request:   GET/c HTTP/1.1
          Response:
          狀態:HTTP/1.1 302 Moved Temporarily
          頭部:Location: http://10.108.10.205:8080/c/portal/layout

          解釋:
          當服務器收到"GET/c"請求后,根據web.xml中的定義,請求會送入MainServlet進行處理。如何生成"/c/portal/layout"有待分析,以后補充,還好不影響大局。

          web.xml
          --------
          <servlet-mapping>
            <servlet-name>MainServlet</servlet-name>
            <url-pattern>/c/*</url-pattern>
          </servlet-mapping>


          3. 第三步,生成 http://10.108.10.205:8080/web/guest/home
          Request:   GET/c/portal/layout HTTP/1.1
          Response:
          狀態:HTTP/1.1 302 Moved Temporarily
          頭部:Location: http://10.108.10.205:8080/web/guest/home

          解釋:
          當服務器收到請求后,同樣會送到MainServlet處理,然后會傳遞到LayoutAction, layout.jsp, portlet.jsp, TemplateProcessor, PortletColumnLogic, load_render_portlet.jsp, portlet_js.jspf,等等,很漫長的,也很有確的一個過程,后面會有單獨的分析,中間仍有一些不明朗的地方,仍有待挖掘。不過不妨礙理清 Liferay的大致經絡。


          4. 第四步,生成網頁
          Request:   GET /web/guest/home HTTP/1.1
          Response: 
          狀態:HTTP/1.1 200 OK
          內容:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
              <html dir="ltr">\n
              <head>\n
              <title>liferay.com - Welcome</title>\n
              <meta content="text/html; charset=UTF-8" http-equiv="content-type" />\r
              <link rel="Shortcut Icon" href="/html/themes/classic/images/liferay.ico" _fcksavedurl=""/html/themes/classic/images/liferay.ico"" />\r
              <link href="/c/portal/css_cached?themeId=classic&colorSchemeId=01&t=1203549390654" type="text/css"

          rel="stylesheet" />\r
              <style type="text/css">\r
              </style>\r
              <script type="text/javascript">\r
              var themeDisplay = {\r
              getCompanyId: function() {\r
              return "10094";\r
              },\r
          ......

          解釋:
          在web.xml中有定義,所以"GET /web/guest/home"請求會由FriendlyURLServlet處理。

          web.xml
          --------
          <servlet>
            <servlet-name>FriendlyURLPublicServlet</servlet-name>
            <servlet-class>com.liferay.portal.servlet.FriendlyURLServlet</servlet-class>
            <init-param>
              <param-name>private</param-name>
              <param-value>false</param-value>
            </init-param>
            <load-on-startup>4</load-on-startup>
          </servlet>
          <servlet-mapping>
            <servlet-name>FriendlyURLPublicServlet</servlet-name>
            <url-pattern>/web/*</url-pattern>
          </servlet-mapping>

          在FriendlyURLServlet.service()方法中,再次將請求傳遞到/c/portal/layout,由LayoutAction進行后續處理。

          FriendlyURLServlet.service()
          -----------------------------
          ServletContext ctx = getServletContext();
          String mainPath = PortalUtil.PATH_MAIN;
          String redirect = mainPath; //redirect = "/c/portal/layout..."
          ......
          RequestDispatcher rd = ctx.getRequestDispatcher(redirect);
          rd.forward(req, res);

           

          Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2177392

          主站蜘蛛池模板: 东乡族自治县| 涪陵区| 钦州市| 化州市| 茂名市| 长乐市| 涟水县| 边坝县| 裕民县| 新河县| 高淳县| 定陶县| 南木林县| 沙湾县| 平泉县| 庆云县| 嫩江县| 澄迈县| 秦安县| 竹北市| 千阳县| 攀枝花市| 蒙山县| 额尔古纳市| 永福县| 杭州市| 翼城县| 叙永县| 北流市| 石林| 罗定市| 门源| 清流县| 鄂尔多斯市| 潍坊市| 布尔津县| 建始县| 大名县| 西乌珠穆沁旗| 扶风县| 镇雄县|