Struts功能详解——ActionMapping对象

Struts旅程(一)Struts简介和原理

实例讲解DispatchAction和LookupDispatchAction

DispatchAction和LookupDispatchAction

Introduction to the Struts Framework

首先说一下Framework的概念:人们用于解决相同或者相似类型问题的方案

特点:可重用行,可扩展性,可收缩性

基于请求响应模式的应用framework的逻辑结构:

1,控制层;

2,业务逻辑层;

3,数据逻辑层

Struts的概念和体系结构:

*    主要采用serlvet和Jsp技术实现的MVC模式

*    很好的一个控制层框架

关于struts其他的介绍就不多说了,先看一张流程图

1,读取配置(初始化ModuleConfig对象)

Struts框架总控制器(ActionServlet)是一个Servlet,在web.xml中配置成自动启动的Servlet,读取配置文件(Struts-config.xml)的配置信息,为不同的Struts模块初始化相应的ModuleConfig对象:

*    ActionConfig

*    ControlConfig

*    FormBeanConfig

*    FowardConfig

*    MessageResourcesConfig

2,发送请求

用户提交表单或调用URL向Web应用程序器提交一个请求,请求的数据用Http协议上传给web服务器

3,填充Form(实例化,复位,填充数据,校验,保存)

(*.do)从ActionConfig中找出对应该请求的Action子类,如没有对应的Action,控制器直接转发给JSP或静态页面,如有对应的Action且这个Action有一个相应的ActionForm,ActionForm被实例化并用HTTP请求的数据填充其属性,并且保存在ServletContext中(request或者session),这样它们就可以被其它Action对象或者JSP调用

4,派发请求

控制器根据配置信息ActionConfig将请求派发到具体的Action,相应的FormBean一并传给这个Action的execute()方法

5,处理业务

Action一般只包含一个execute()方法,它负责执行相应的业务逻辑(调用其他业务模块),完毕后返回一个ActionForward对象,控制器通过该ActionForward对象来进行转发工作

6,返回响应

Action根据业务处理的不同结果返回一个目标响应对象给总控制器,该目标响应对象对应一个具体的JSP页面或者另一个Action

7,查找响应(翻译响应)

总控制器根据业务功能Action返回的目标响应对象,找到对应的资源对象,通常是一个具体的JSP页面

8,响应用户

目标响应对象将结果展现给用户目标响应对象(jsp),将结果页面展现给用户。

Struts Components

The Controller

This receives all incoming requests. Its primary function is the mapping of a request URI to an action class selecting the proper application module. It's provided by the framework.

The struts-config.xml File

This file contains all of the routing and configuration information for the Struts application. This XML file needs to be in the WEB-INF directory of the application.

Action Classes

It's the developer's responsibility to create these classes. They act as bridges between user-invoked URIs and business services. Actions process a request and return an ActionForward object that identifies the next component to invoke. They're part of the Controller layer, not the Model layer.

View Resources

View resources consist of Java Server Pages, HTML pages, JavaScript and Stylesheet files, Resource bundles, JavaBeans, and Struts JSP tags.

ActionForms

These greatly simplify user form validation by capturing user data from the HTTP request. They act as a "firewall" between forms (Web pages) and the application (actions). These components allow the validation of user input before proceeding to an Action. If the input is invalid, a page with an error can be displayed.

Creating an ActionForm Bean

A Struts ActionForm bean is used to persist data between requests. For example, if a user submits a form, the data is temporarily stored in the form bean so that it can either be redisplayed in the form page (if the data is in an invalid format or if login fails) or displayed in a login success page (if data passes validation).

ActionForm

(二)、普通HTML表单使用Form的工作原理
ActionServlet 对struts-config进行解析时,当解析到某个action中存在一个属性name,那么ActionServlet中的 RequestProcessor就会根据该name的值找到对应的form-bean然后创建一个对应的form类实例,放在我们定义的存储范围中,当 表单提交到该action对应的appAction之前也就是到达FC的时候,FC会做以下事情
1.根据路径找到对应的内存中存放着的配置对象中的action
2.根据action中的attribute属性,从session中得到一个对应的form实例
3.该form实例调用reset方法对自己进行清空
4.用表单中的值去填充该form实例
5.如果要该form要进行验证那么就该form就会调用validate方法按照我们规定的验证规则进行验证

(三)、struts表单使用Form的工作原理
1. 利用struts的HTML标签库定义的HTML元素其实是服务器端的java代码,java代码是编译型代码而HTML则是解释型代码,所以在使用 struts的HTML标签库定义的HTML元素要更加的严谨,只要某个元素甚至是某个属性没有定义对,那么编译就不能通过从而抛出异常,例如在使用 struts的HTML标签库定义表单的时候action属性是在编译的时就要被确定的如果action属性所定义的提交路径是空或者是错误,那么服务器 在编译的时候就会抛出500的异常,而不像普通HTML表单action属性是在提交的时候才确定的
2.原理跟普通HTML表单使用Form的工 作原理大同小异,不同在于当服务器对form表单进行编译的时候会向action所指定的地址发一个请求,看是否正确,所以这个时候其实就已经提交了一次 表单,当表单到达FC的时候跟上面做的几件事情中就第三件不同,不同在于表单和form中的值都将互相填充,这就是struts对表单的回添机制

Struts framework的更多相关文章

  1. custom struts framework

    1. Difference between stucts1 and struts2 struts1 : Servlet used as Controller , you can visit the S ...

  2. Struts 2 Learning

    目录 . J2EE简介 . JAVA EE应用的分层模型 . 搭建Struts2 Demo应用 . struts2流程 . struts2的常规配置 . 实现Action . 配置Action . 配 ...

  3. Struts和SpringMVC两种MVC框架比较

    基于Web的MVC framework在J2EE的世界内已是空前繁荣.TTS网站上几乎每隔一两个星期就会有新的MVC框架发布.目前比较好的MVC,老牌的有Struts.Webwork.新兴的MVC框架 ...

  4. Configure the Struts Tag Libraries

    In Struts framework, you always need to configure the Struts tag libraries in order to access it in ...

  5. Struts知识问答 分类: 面试 2015-07-10 22:01 4人阅读 评论(0) 收藏

    1. 简述Struts框架的初始化流程. 答案: 对于采用Struts框架的Web应用,在Web应用启动时就会加载并初始化控制器ActionServlet ActionServlet从struts-c ...

  6. struts工作原理不错的解释___

    Struts 使用 Model 2 架构.Struts 的ActionServlet 控制导航流.其他Struts 类,比如Action, 用来访问业务逻辑类.当 ActionServlet 从容器接 ...

  7. Struts 2 Overview

    Struts2 is popular and mature web application framework based on the MVC design pattern. Struts2 is ...

  8. Spring+Struts+Hibernate 简介(转)

    http://blog.csdn.net/slnqnd/article/details/1772910/ Struts2.0 +Hibernate 3.2 +Spring 2.0 一.         ...

  9. 概述struts,以及struts如何实现MVC架构的

    概述MVC体系结构? 答:MVC包括三类对象,model是应用对象,view是视图,controller是控制器,它定义用户界面对用户输入的响应方式. 在MVC体系中,模型通常被称为”业务逻辑”,是真 ...

随机推荐

  1. java基础之BigDecimal类

    由于在运算的时候,float类型和double很容易丢失精度,演示案例.所以,为了能精确的表示.计算浮点数,Java提供了BigDecimal BigDecimal类概述 不可变的.任意精度的有符号十 ...

  2. ElasticSearch入门之花落红尘(三)

    上篇文章散仙介绍了ElasticSearch的入门安装和使用,那么本篇我们来看下,如何使用java api来和ElasticSearch进行交互,简单点说,就是实现一个增删改查,来找找入门的感觉. 在 ...

  3. PIL的ImageDraw的颜色问题

    因为我的图片的单通道的,所以用 draw = ImageDraw.Draw(image) im_width, im_height =], info[], info[], info[]) color=d ...

  4. Windows API 第17篇 GetLogicalDriveStrings 获取本机所有逻辑驱动器,以根目录的形式表示

    函数原型:DWORD GetLogicalDriveStrings(  DWORD nBufferLength,  // size of buffer                          ...

  5. Drupal创建Omega 4.x 子主题layout笔记

    Adding a new region to your Omega 4.0 subtheme (Drupal) Drupal: Creating a custom layout with Omega ...

  6. [转]WPF焦点概述

    WPF 中,有两个与焦点有关的主要概念:键盘焦点和逻辑焦点. 键盘焦点指接收键盘输入的元素,而逻辑焦点指焦点范围中具有焦点的元素. 本概述将详细介绍这些概念. 理解这些概念之间的区别对于创建具有可以获 ...

  7. idea打包可执行jar

    (1)在项目上鼠标右键 --> Open Module Settings 或者点击工具栏上的 (2)Artifacts --> + --> JAR --> From modul ...

  8. 大牛就别进来了.npm --save-dev --save 的区别

    --save-dev 是你开发时候依赖的东西,--save 是你发布之后还依赖的东西. 比如,你写 ES6 代码,如果你想编译成 ES5 发布那么 babel 就是devDependencies.如果 ...

  9. Laravel 错误处理

    错误提示:cURL error 60: SSL certificate problem: unable to get local issuer certificate 解决方案:修改文件,重启队列即可 ...

  10. 位操作(求[a, b] 中二进制位为1的个数最多的数)

    传送门 题意:求区间[a, b]中二进制位为1的个数最多的那个数,如果存在多解,则输出最小的那个.(0 <= a <= b) 关键: 对一个数a可以利用 a | (a + 1) 来将a的二 ...