本文从收到一个请求开始讲述,忽略之前的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. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词

    #coding:utf-8 import os,re path = 'test' files = os.listdir(path) def count_word(words): dic = {} ma ...

  2. selenium 学习笔记 ---新手学习记录(4) 问题总结(java)-autoit3脚本使用

    1.安装autoit3 下载地址:点我下载 (提取码:9633) 提取码 下载完成后,一直下一步即可 2.上传头像使用脚本 代码如下: ControlFocus("打开",&quo ...

  3. Git Command Summary (Updated)

    取得Git仓库 初始化一个版本仓库 git init Clone远程版本库 git clone git@xbc.me:wordpress.git 添加远程版本库origin,语法为 git remot ...

  4. linux下挂载第二块硬盘

    1.第一步:添加硬盘/新建分区(fdisk) a.查看当前系统所有硬盘及分区情况:fdisk -lb.在指定的硬盘(例:/dev/sda)上创建分区:fdisk /dev/sda , 根据提示进行下一 ...

  5. 牛人眼中如何精通spring?

    现在市场上,spring框架很火,很多公司面试题直接将spring中某个api拿出来考面试人员,我去东南融通就遇到了这个情况,我拒绝做这些没有水准的试题,如果公司非让让我做,我想这样的公司也不值得我来 ...

  6. GCD自己做的一些简单总结

    GCD总结 GCD  Grand Central Dispatch  牛逼的中枢调度器 GCD中各种队列的执行效果 想看线程  必须是异步函数  并且不是主队列 注意:使用sync函数往当前串行队列添 ...

  7. python小游戏实现代码

    早上逛CSDN首页就见到这么一篇教程.看了一下很有意思,就马上动手实现了一下.看看效果吧: 完整代码: # -*- coding: utf-8 -*- # 1 - Import library imp ...

  8. vector数据查找方法

    用STL编敲代码时常常使用vector容器来存储数据.当容器中的数据有序时我们能够採取两种方式: (1) 利用<algorithm>中的find函数进行查找: (2) 折半查找. 另外也能 ...

  9. vue开发体验

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  10. 关于Comparable接口的使用

    一.使用Comparable接口进行排序:如何要都某种数据类型或者是自定义的类进行排序必须要实现Comparable jdk定义的基本数据类型和String类型的数据都实现了Comparable.下面 ...