---
title: "jeecms加载首页的过程"
author: "davice_li"
date: "2010-12-30T22:05:20Z"
tags: ["CMS", "Struts", "Web", "Webwork", "freemarker"]
categories: ["编程语言"]
slug: "jeecms"
draft: false
lastmod: "2010-12-30T22:05:20Z"
id: 856337
url: "https://davice-li.iteye.com/blog/856337"
---

# ![原创](http://blog.csdn.net/images/authorship.gif)  jeecms加载首页的过程 [收藏](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx "收藏到我的网摘中，并分享给我的朋友")

&lt; src="http://hi.images.csdn.net/js/blog/tiny\_mce/plugins/syntaxhl/langs/zh.js" type="text/javascript"&gt; 刚开始研究jeecms的时候很纳闷，找不到首页的加载页面。。经过一番仔细研究，发现这个加载还是经过了很多曲折的过程的。整个程序的架构师ssh+freemarker模板构成的，所以先要熟悉freemarker模板技术。

先看web.xml文件，其中欢迎页面有：

[+ expand source](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[view plain](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[copy to clipboard](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[print](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[?](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)

 

接着再看jeecms/core/struts-front.xml配置文件，发现有个action的通用配置：

[view plain](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[copy to clipboard](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[print](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[?](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)

01. &lt;action name="\*\*" class="core.dynamicSystemAct"&gt;
02. &lt;result type="chain"&gt;
03. &lt;param name="namespace"&gt;${namespace}&lt;/param&gt;
04. &lt;param name="actionName"&gt;${actionName}&lt;/param&gt;
05. &lt;/result&gt;
06. &lt;interceptor-ref name="exception"/&gt;
07. &lt;interceptor-ref name="domain"/&gt;
08. &lt;interceptor-ref name="cookieIdentity"/&gt;
09. &lt;interceptor-ref name="url"/&gt;
10. &lt;/action&gt;

 

struts收到请求以后，将请求转发到core.dynamicSystemAct这个对象，注意这个这个class并不是真正的类，是类的别名，由spring通过标注@Controller进行绑定，web应用上下文可以通过classpath自动扫描到这个类。

[view plain](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[copy to clipboard](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[print](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[?](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)

1. @Controller("core.dynamicSystemAct")
2. public class DynamicSystemAct

 

在这个action执行之前，先要执行好几个拦截器。其他struts和webwork自带的拦截器不必说，主要说一下在程序里面自定义的几个比较重要的拦截器（定义在jeecms/src/struts-default.xml文件中）。

DomainNameInterceptor

UrlInterceptor

CookieIdentityInterceptor

然后执行action自己的execute方法，产生2个参数：

namespace = "/jeedynamic/" + sys;

actionName = "Page";

这2个参数决定了程序的走向，组成转发路径：/jeedynamic/jeecms/Page.do，然后通过查找下面的配置信息

[view plain](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[copy to clipboard](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[print](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)[?](http://blog.csdn.net/zhaozhenhua88/archive/2009/09/21/4578151.aspx)

1. &lt;package name="cms.front.page" namespace="/jeedynamic/jeecms" extends="empty-default"&gt;
2. &lt;action name="Page" class="cms.cmsPageAct"&gt;
3. &lt;result&gt;${tplPath}&lt;/result&gt;
4. &lt;result name="pageCache" type="pageCache"&gt;${tplPath}&lt;/result&gt;
5. &lt;interceptor-ref name="exception"/&gt;
6. &lt;interceptor-ref name="chain"/&gt;
7. &lt;/action&gt;
8. &lt;/package&gt;

 

 

**注：其他的请求过程类似，先找到命名空间，然后找到对应的acting进行处理。**

将请求转发给cms.cmsPageAct对象，同上的道理，对应到控制器：com.jeecms.cms.action.front.CmsPageAct。拦截器处理完毕后，执行自己的execute方法，判断若是首页，则执行sysIndex（）方法，返回一个模板路径tplPath：/WEB-INF/user\_base/jeecms\_com\_www/template/article/default/index.html，找到这个文件，是文章对应的首页模板，里面有自定义的freemarker标签@cms，定义在配置文件freemarker.properties中:

auto\_import="/WEB-INF/ftl\_lib/ponyjava.com/index.ftl" as p, "/WEB-INF/ftl\_lib/jeecms/index.ftl" as cms 

@cms标签所用的ftl模板文件为index.ftl。 打开index.ftl文件，includes了多个ftl，其中有action\_cms.ftl，该文件用标签#macro，自定义许多directive：ChnlList和CommentList等。里面使用struts2标签@s.action来请求数据，整个的index.html页面就是这么加载出来的。通过freemarker引擎来解析数据模型，最后显示到前台，展现给客户