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. Vuejs之Component slot 插槽详解

    Vuejs的component的数据进行了沙箱隔离,除js全局变量如Math, Date之类外无法访问用户自定义的变量,所以使用component写组件或嵌套组件时明白变量的访问非常重要 编译作用域 ...

  2. 解决Navicat 报错:1130-host is not allowed MySQL不允许从远程访问的方法

    ERROR 1130: Host '192.168.1.3' is not allowed to connect to thisMySQL server 解决方法: 1. 改表法.可能是你的帐号不允许 ...

  3. elasticsearch 中文API facets(⑩)

    facets Elasticsearch提供完整的java API用来支持facets.在查询的过程中,将需要计数的facets添加到FacetBuilders中.然后将该FacetBuilders条 ...

  4. pandas一些基本操作(DataFram和Series)_3

    import pandas as pd;import numpy as np#通过一维数组创建Chinese = np.array([89,87,86])print(Chinese)print(pd. ...

  5. 使用ResponseEntity进行返回json数据

    在最近的项目中,与上位机进行数据传输时,上位机需要服务器的响应得知服务器是否正常运行,数据是否正常发送 在最近的调试中我使用ResponseEntity<Map<String,Object ...

  6. python基础-logging应用

    import logging.config BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))LOG_PATH=o ...

  7. 网络流Sap算法

    GDKOi就快要开始了.没时间打解析,直接上模板. #include <cstdio> #include <cstring> #include <algorithm> ...

  8. Java发送http请求发送json对象

    直接上代码: http工具类: public static String httpPostWithjson(String url, String json) throws IOException { ...

  9. day48作业

    使用Bootstrap框架编写一个简单的web静态页面 效果图: <!DOCTYPE html> <html lang="en"> <head> ...

  10. SQL Server数据库存储过程的异常处理

    SQL Server数据库存储过程的异常处理是非常重要的,明确的异常提示能够帮助我们快速地找到问题的根源,节省很多时间.本文我们就以一个插入数据为例来说明SQL Server中的存储过程怎么捕获异常的 ...