本文从收到一个请求开始讲述,忽略之前的filter等工作.

处理工作的主要承担者为RequestProcessor

1.处理请求的url. RequestProcessor.processPath(request,response)
  String path = processPath(request, response);

     protected String processPath(HttpServletRequest request,
HttpServletResponse response)
throws IOException { String path = null; // For prefix matching, match on the path info (if any)
path = (String) request.getAttribute(INCLUDE_PATH_INFO);
if (path == null) {
path = request.getPathInfo();
}
if ((path != null) && (path.length() > 0)) {
return (path);
} // For extension matching, strip the module prefix and extension
path = (String) request.getAttribute(INCLUDE_SERVLET_PATH);
if (path == null) {
path = request.getServletPath();
}
String prefix = moduleConfig.getPrefix();
if (!path.startsWith(prefix)) {
String msg = getInternal().getMessage("processPath"); log.error(msg + " " + request.getRequestURI());
response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); return null;
} path = path.substring(prefix.length());
int slash = path.lastIndexOf("/");
int period = path.lastIndexOf(".");
if ((period >= 0) && (period > slash)) {
path = path.substring(0, period);
}
return (path); }

  从request中获取请求的url.path = request.getPathInfo();

  在对获取的path进行处理:

         path = path.substring(prefix.length());
2 int slash = path.lastIndexOf("/");
3 int period = path.lastIndexOf(".");
if ((period >= 0) && (period > slash)) {
path = path.substring(0, period);
}
return (path);

2.根据获取的url-path来构建ActionMapping

  ActionMapping mapping = processMapping(request, response, path);  

  

    protected ActionMapping processMapping(HttpServletRequest request,
HttpServletResponse response,
String path)
throws IOException { // Is there a mapping for this path?
ActionMapping mapping = (ActionMapping)
moduleConfig.findActionConfig(path); // If a mapping is found, put it in the request and return it
if (mapping != null) {
request.setAttribute(Globals.MAPPING_KEY, mapping);
return (mapping);
} // Locate the mapping for unknown paths (if any)
ActionConfig configs[] = moduleConfig.findActionConfigs();
for (int i = 0; i < configs.length; i++) {
if (configs[i].getUnknown()) {
mapping = (ActionMapping) configs[i];
request.setAttribute(Globals.MAPPING_KEY, mapping);
return (mapping);
}
} // No mapping can be found to process this request
String msg = getInternal().getMessage("processInvalid");
log.error(msg + " " + path);
response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); return null;
}

  这个过程主要是从struts-config.xml中读取<action-mapping>结点的action信息,将所有的<action>结点保存到ActionMapping中.

3.获取ActionForm,

   ActionForm form = processActionForm(request, response, mapping);

  上一步通过url已经定位到了相应的action,然后通过 String name = mapping.getName(); 获取actionform(该项在<form-beans>中获取),同时设置该action的作用域(request/session默认session).再将创建号的actionform放到request/session中.

4.从actionform中获取相应的值,完成相应数据的赋值,这其中包括类型的转换,使用了第三方的工具类BeanUtils.

5.创建相应的action

  protected Action processActionCreate(HttpServletRequest request,HttpServletResponse response,ActionMapping mapping)

  actionform信息存在于actionmapping中。首先根据action类的完整名称(<action>标签下面的type),如果已经存在直接返回;否则再使用反射机制创建action。

6.最终执行action的execute方法。

  ActionForward forward =processActionPerform(request, response,action, form, mapping);

  从中执行action的execute方法,返回actinforward,再根据返回的actionforward来实现转发/转向。

具体的处理流程如下图:

附件一 struts-config.xml

<struts-config>
<form-beans>
<form-bean name="loginactionform" type="com.volshell.actionform.LoginActionForm"/>
</form-beans>
<action-mappings>
<action path="/login"
name="loginactionform"
type="com.volshell.action.LoginAction"
scope="request">
<forward name="error" path="/login_fail.jsp"></forward>
<forward name="success" path="/login_success.jsp"></forward>
</action>
</action-mappings>
</struts-config>

Struts1的处理流程的更多相关文章

  1. ActionErrors 使用说明 struts1 validate 处理流程 详细教程(转)

    转自(http://blog.csdn.net/wyx100/article/details/8736445). struts1  处理流程是  jsp  -->  ActionForm 中的A ...

  2. Struts1简单开发流程梳理

    共享数据的4种范围MVC设计模式JSP model1.JSP model2struts实现MVC机制(ActionServlet.Action)struts-config.xml ActionServ ...

  3. Struts1的实现原理

    一 开文背景 -- 废话讲一段~ 本文借助动力节点-王勇老师的视频教程中的引例来了解struts1的实现原理,虽然现在已经很少使用struts1了,但是了解了其原理之后,对了解其他mvc框架还是有较大 ...

  4. struts2和struts1认识

    1.Struts 2基本流程 Struts 2框架本身可以大致分3部分:核心控制器FilterDispatcher.业务总监Action与用户实现企业业务逻辑组件. 核心控制器FilterDispat ...

  5. Struts1、WebWork、Struts2介绍

    一.Struts1 1.Struts1原理简介 Struts1框架以ActionServlet作为控制器核心,整个应用由客户端请求驱动.当客户端向Web应用发送请求时,请求被Struts1的核心控制器 ...

  6. Struts1的基础知识

    struts1.0的配置 在web.xml文件中的配置 <servlet> <!--配置ActionServlet类,一启动就创建该类对象--> <servlet-nam ...

  7. 深入了解Struts1的执行机理

    要说Struts1的工作流程.就必需要说一下Model1和Model2了.由于这个框架是踏着他们的尸骨一步一步的发展起来的. Model1开发模式,想想我们刚刚開始接触Java的时候,我们用的就是这样 ...

  8. Struts1 MVC框架的工作原理

    MVC英文及Model-View-Controller,分别是模型(Model),视图(View)和控制(Controller).MVC模式的目的是实现web系统的职能分工. View:即用户交互界面 ...

  9. SSH-Struts第三弹:传智播客视频教程第一天上午的笔记

    一. 框架概述1.三大框架 : 是企业主流 JavaEE 开发的一套架构 Struts2 + Spring + Hibernate 2. 什么是框架?为什么要学框架 ?框架 是 实现部分功能的代码 ( ...

随机推荐

  1. codeforces 375D . Tree and Queries 启发式合并 || dfs序+莫队

    题目链接 一个n个节点的树, 每一个节点有一个颜色, 1是根节点. m个询问, 每个询问给出u, k. 输出u的子树中出现次数大于等于k的颜色的数量. 启发式合并, 先将输入读进来, 然后dfs完一个 ...

  2. Python主要模块和常用方法简览

    原文地址:http://blog.csdn.net/hwhjava/article/details/22284399 PY核心模块方法1. os模块: os.remove() #删除文件 os.unl ...

  3. IList, ICollection ,IEnumerable AND IEnumerator in C#

    IList, ICollection ,IEnumerable 很显然,这些都是集合接口的定义,先看看定义: // 摘要: // 表示可按照索引单独访问的对象的非泛型集合. [ComVisible(t ...

  4. cocoapod的安装与使用

    cocoaPods的使用 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...

  5. linux所有信息查询网址

  6. Oracle10g任务调度创建步骤

    /* 创建可执行程序 */begin DBMS_SCHEDULER.CREATE_PROGRAM( program_name => 'peace_sj_his.PROG_DATASYNC', p ...

  7. HDU 1358 Period KMP

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1358 求周期问题,简单KMP—— AC代码: #include <iostream> # ...

  8. citrix协议ICA技术原理

    转载自: http://www.zrss.com.cn/article-110-1.html Citrix交付中心解决方式的核心是虚拟化技术,虚拟化计算的核心是ICA协议,ICA协议连接了执行在平台上 ...

  9. C++ 函数映射使用讲解

    想想我们在遇到多语句分支时是不是首先想到的是 switc case 和 if else if ... 这2种方式在编码方面确实简单少,但是当分支达到一定数量后,特别是分支内部有嵌套大段代码或者再嵌套分 ...

  10. js中函数参数基本类型和引用类型的区别

    高级程序设计中说明,所有函数的参数都是按值传递的. 基本类型 向参数传递基本类型的值时,被传递的值会被复制给对应的命名参数 function addTen(num){ num=+10; return ...