Struts1的处理流程
本文从收到一个请求开始讲述,忽略之前的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的处理流程的更多相关文章
- ActionErrors 使用说明 struts1 validate 处理流程 详细教程(转)
转自(http://blog.csdn.net/wyx100/article/details/8736445). struts1 处理流程是 jsp --> ActionForm 中的A ...
- Struts1简单开发流程梳理
共享数据的4种范围MVC设计模式JSP model1.JSP model2struts实现MVC机制(ActionServlet.Action)struts-config.xml ActionServ ...
- Struts1的实现原理
一 开文背景 -- 废话讲一段~ 本文借助动力节点-王勇老师的视频教程中的引例来了解struts1的实现原理,虽然现在已经很少使用struts1了,但是了解了其原理之后,对了解其他mvc框架还是有较大 ...
- struts2和struts1认识
1.Struts 2基本流程 Struts 2框架本身可以大致分3部分:核心控制器FilterDispatcher.业务总监Action与用户实现企业业务逻辑组件. 核心控制器FilterDispat ...
- Struts1、WebWork、Struts2介绍
一.Struts1 1.Struts1原理简介 Struts1框架以ActionServlet作为控制器核心,整个应用由客户端请求驱动.当客户端向Web应用发送请求时,请求被Struts1的核心控制器 ...
- Struts1的基础知识
struts1.0的配置 在web.xml文件中的配置 <servlet> <!--配置ActionServlet类,一启动就创建该类对象--> <servlet-nam ...
- 深入了解Struts1的执行机理
要说Struts1的工作流程.就必需要说一下Model1和Model2了.由于这个框架是踏着他们的尸骨一步一步的发展起来的. Model1开发模式,想想我们刚刚開始接触Java的时候,我们用的就是这样 ...
- Struts1 MVC框架的工作原理
MVC英文及Model-View-Controller,分别是模型(Model),视图(View)和控制(Controller).MVC模式的目的是实现web系统的职能分工. View:即用户交互界面 ...
- SSH-Struts第三弹:传智播客视频教程第一天上午的笔记
一. 框架概述1.三大框架 : 是企业主流 JavaEE 开发的一套架构 Struts2 + Spring + Hibernate 2. 什么是框架?为什么要学框架 ?框架 是 实现部分功能的代码 ( ...
随机推荐
- codeforces 557D. Vitaly and Cycle 二分图染色
题目链接 n个点, m条边, 问最少加几条边可以出现一个奇环, 在这种情况下, 有多少种加边的方式. 具体看代码解释 #include<bits/stdc++.h> using names ...
- Python主要模块和常用方法简览
原文地址:http://blog.csdn.net/hwhjava/article/details/22284399 PY核心模块方法1. os模块: os.remove() #删除文件 os.unl ...
- JS 原型 & 继承
理解原型链 先看看http://www.ituring.com.cn/article/56184和http://www.cavabiao.com/prototype-and-inherit-of-ja ...
- inline-block 垂直居中
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python2.6升级到2.7
开发部需要使用python2.7,由于公网的环境python版本都是系统自带的,版本是2.6,需要升级,最好是通过RPM升级. Linux系统:CentOS CentOS 6.4升级Python后yu ...
- HDU 1286 找新朋友
题解:分析题目,就是一个裸的欧拉函数,于是AC. #include <cstdio> int eular(int n){ int ret=1,i; for(i=2;i*i<=n;i+ ...
- Visual Studio Tip: Get Public Key Token for a Strong Named Assembly
The first 3 parts are easy to get. I should know the name, version, and culture for the assembly sin ...
- asp.net MVC 使用JQuery.Ajax
使用到:Jquery.js 以及 Newtonsoft.Json.dll 客户端调用方式: $("#ButAjax").click(function() {$.ajax({type ...
- dedecms的入门使用
前段时间(其实也很远了)一直在学习dedecms,这里对前段时间的学习做一个总结. dedecms学习网址:http://help.dedecms.com/v53
- opencv第一站:配置opencv环境(2015-12-12)
今天论坛申请的书< OpenCV 计算机视觉编程攻略(中国工信出版社)>到了,准备研究研究机器视觉. 晚上安装了 vc2008 及 opencv 最新版 3.0.0,试了各种配置都是错误提 ...