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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n
    <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

posted on 2008-03-14 14:11 礼物 阅读(1463) 评论(0)  编辑  收藏 所属分类: Liferay