除了tag基本上研究了一下,一开始不要看tag,从它那个controller入手,然后看它处理xml配置(这个一开始也可以跳过),然后就是看它的影射处理,原码没必要完全搞清楚,主要是学习整个系统的架构(struts的一些代码真的是写得很漂亮)

解决方案 »

  1.   

    主要把精力放在struts的框架上。一定要结合MVC模式一起看。这样才有比较。看看struts是怎样实现视图控制和事务逻辑分离的。
    细节上主要把握struts-config.xml,ActionServlet,ActionForm,Action.
    至于标签库要慢慢看,不能性急。
      

  2.   

    如果搞开发,不用研究太深用eclipse+xdoclet+struts
    基本上是jsp->formBean->actionBean->jsp的逻辑。
    formBean可以取出jsp表单数据。actionBean作数据处理和视图控制
      

  3.   

    ActionServlet是控制中心,也是研究源程序的重点中的重点。
    其中又有两个工作是ActionServlet的核心工作。
    1、ActionServlet初始化工作,其中initServlet是重要的函数之一,另外就是init开发的其它几个函数。
    2、在ActionServlet中主要是调用了RequestProcessor的process函数进行一些请求处理:
    public void process(HttpServletRequest request,
                            HttpServletResponse response)
            throws IOException, ServletException {        // Wrap multipart requests with a special wrapper
            request = processMultipart(request);        // Identify the path component we will use to select a mapping
            String path = processPath(request, response);
            if (path == null) {
                return;
            }
            if (log.isDebugEnabled()) {
                log.debug("Processing a '" + request.getMethod() +
                          "' for path '" + path + "'");
            }        // Select a Locale for the current user if requested
            processLocale(request, response);        // Set the content type and no-caching headers if requested
            processContent(request, response);
            processNoCache(request, response);        // General purpose preprocessing hook
            if (!processPreprocess(request, response)) {
                return;
            }        // Identify the mapping for this request
            ActionMapping mapping = processMapping(request, response, path);
            if (mapping == null) {
                return;
            }        // Check for any role required to perform this action
            if (!processRoles(request, response, mapping)) {
                return;
            }        // Process any ActionForm bean related to this request
            ActionForm form = processActionForm(request, response, mapping);
            processPopulate(request, response, form, mapping);
            if (!processValidate(request, response, form, mapping)) {
                return;
            }        // Process a forward or include specified by this mapping
            if (!processForward(request, response, mapping)) {
                return;
            }
            if (!processInclude(request, response, mapping)) {
                return;
            }        // Create or acquire the Action instance to process this request
            Action action = processActionCreate(request, response, mapping);
            if (action == null) {
                return;
            }        // Call the Action instance itself
            ActionForward forward =
                processActionPerform(request, response,
                                     action, form, mapping);        // Process the returned ActionForward instance
            processForwardConfig(request, response, forward);    }从上面的代码基本上可看出了处理请求的过程,从数据验证到action现到转发。
    这里是你研究Struts源程序要注意的核心部分。******************************
    ActionServlet提供了公共方法,可以被Action类实例使用。本节我们简要讨论一些方法:关于ActionServlet方法的更详细信息,请参数在http://jakarta.apache.org/struts中的Struts文档。
    ActionServlet有允许我们增加或删除ActionForm beans、ActionForwards和ActionMappings的方法。这些方法的基本形式如下所示:
    public void addFormBean(ActionFormBean formBean)
    public void removeBean(ActionFormBean formBean)
    public void addForward(ActionForward forward)
    public void removeForward(ActionForward formward)
    public void addMapping(ActionMapping mapping)
    public void removeMapping(ActionMapping mapping)
    每个定义显示了方法的范围(都是public)、方法返回的对象(都为void)以及方法的参数,下列方法根据名字找到这些对象:
    public ActionFormBean findFormBean(String name)
    public ActionForward findForward(String name)
    public ActionMapping findMapping(String name)
    接下来的两个方法用于处理数据源:
    public void addDataSource(String key,DataSource ds)
    public Datasource findDataSource(String key) – trturns a DataSource instance
    findDataSource()方法用名字查找数据源。数据源可能是在Struts配置文件中静态定义的,也可能是用addDataSource()方法动态增加的。
    最后,我们可以用下列的destroy()方法很优雅地关闭ActionServlet,并用reload()方法从Struts配置文件中重新装入信息到ActionServlet。*********************************************
     ActionSetvlet是控制器主要组成部分,它由Struts类org.apache.struts.action. ActionServlet实现。这个类继承了标准javax.servlet.http.HttpServlet类。在处理请时控制器完成下列任务:
        1.为到来的请求找到请求URI
    2.把URI映射到适当的ActionMapping
    3.创建或找到封装为当前映射定义的所有信息的ActionMapping实例
    4.如果在映射中声明了的话,创建或找到ActionForm bean实例,用request参数去试着产生一个bean的属性。
    5.对在ActionMapping中声明的Action类实例调用适当的perform()方法,给它传递ActionForm bean(如果在映射中声明)、ActionMapping对象、request对象和response对象。
    6.接受从perform()方法返回的ActionForward,转发response到由ActionForward指定的源。
      

  4.   

    爱好STRUTS的朋友留个联系方式吧:)
     MSN :[email protected]
     qq  : 57473763
      

  5.   

    如果你对JSP很熟悉了;
    STRUTS学起来就很快的;如果要精通,就要不断的做。
      

  6.   

    可以先了解其中的MVC模式,然后再看controller(也就是ActionServlet),理解它是怎样接收请求并将其分发给对应该的Action.
    了解这个之后,那就是看Taglib了,还有……
      

  7.   

    我现在在搞JSP引擎,不过对STRUTS也不是很明了,希望大家多多交流.
    我的MSN是[email protected]
    不过我不喜欢目空一切,代码又写不出或写出也是一堆SHIT的人,也不喜欢只会说人怎样,不知自己怎样的人。
      

  8.   

    ActionServlet 的init方法将struts-config.xml用degester解析后压入了一个ModuleConfig的类型的对象中,然后通过反射来实现form,action类的实例从而用来实现数据装载和request的分发。这是我一点理解
      

  9.   

    可以去找找 孤魂一笑 的一篇关于他看Struts源码的体会. 对不起我忘了名字了.记得在java中文站看到的.