struts2 实现过程和xml配置

实现过程:

Web容器收到 请求(HttpServletRequest)它将请求传递给一个标准的的过滤链包括

(ActionContextCleanUp)过滤器,然后经过Other filters(SiteMesh ,etc),接下来需要调用FilterDispatcher核心控制器,然后它调用ActionMapper确定请求哪个Action,ActionMapper返回一个收集Action详细信息的ActionMaping对象。

接下来FilterDispatcher将控制权委派给ActionProxy,ActionProxy调用配置管理器(ConfigurationManager) 从配置文件中读取配置信息(struts.xml),然后创建ActionInvocation对象,ActionInvocation在调用Action之前会依次的调用所用配置拦截器(Interceptor N) 一旦执行结果返回结果字符串ActionInvocation负责查找结果字符串对应的(Result)然后执行这个Result Result会调用一些模版(JSP)来呈现页面,之后拦截器(Interceptor N)会再被执行(顺序和Action执行之前相反)最后响应(HttpServletResponse)被返回在web.xml中配置的那些过滤器和(核心控制器)(FilterDispatcher)。

action类:

描述业务逻辑,其中execute()方法返回一个字符串值,如sucess

struts.xml  :将所有东西如jsp  action 等连在一起。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<package name="user" namespace="/User" extends="struts-default">
		<action name="Login">
			<result>/login.jsp</result>
		</action>
		<action name="Welcome" class="com.yiibai.user.action.WelcomeUserAction">
			<result name="SUCCESS">/welcome_user.jsp</result>
		</action>
	</package>
</struts> 

web.xml:配置Web应用程序部署描述符(web.xml)文件Struts2的集成到Web项目

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name></display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
  	<filter-name>struts2</filter-name>
  	<filter-class>
  		org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  	</filter-class>
  </filter>
  <filter-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>*.action</url-pattern>
  </filter-mapping></web-app>
时间: 2024-08-26 05:38:10

struts2 实现过程和xml配置的相关文章

Spring IOC的初始化过程——基于XML配置(一)

前言:在面试过程中,Spring IOC的初始化过程,基本上属于必答题,笔者的亲身经历.因此本文基于Spring的源码对其IOC的初始化过程进行总结. 注:spring版本为4.3.0. 1.调试前准备 在spring源码中,添加如下内容(有关spring源码如何导入idea,请查询相关资料): 说明: ①User为简单bean,含有name和gender两个属性. ②User.xml为spring配置文件,仅仅对User进行简单的配置. ③SpringIoCDebug为测试类. 先看执行结果:

Struts2 学习笔记——struts.xml文件之Bean的配置

Struts2的大部分核心组件不是以硬编码的形式写在代码中,而是通过自身的IoC容器来管理的. Struts2以可配置的形式来管理核心组件,所以开发者可以很容易的扩展框架的核心组件.当开发者需要扩展或者替换Struts2的核心组件时,只需要提供自己的组件实现类,并部署在Struts2的IoC容器中即可. 我们打开struts2-core-2.2.1.1.jar中的struts-default.xml文件,可以看到大量的Bean的定义.如下代码片段: <struts> <!—- 两个对象工

解决struts2中validation.xml配置无效的问题

解决struts2中validation.xml配置无效的问题,我使用了xml的验证,却始终发现无法生效,后面发现才是xml的头文件的格式问题,修改了一下就好了. 成功的xml <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd"> <val

Struts2返回json数据xml中配置

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <!-- 登陆配置

struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)

一.web.xml配置 <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-val

Struts2 XML配置详解

struts官网下载地址:http://struts.apache.org/ 1.    深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1.    包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管理Action和拦截器等.每个包就是多个Action.多个拦截器.多个拦截器引用的集合. 在struts.xml文件中package元素用于定义包配置,每个package元素定义了一个包配置.它的常用属性有: l name

【struts2.5配置】web.xml配置

一.引用jar包 1. 将下载好的struts下的核心类库复制到/WEB-INF/lib目录下 二.web.xml配置 check your struts2-core-x.x.jar version. -->if it is struts2-core-2.5.jar then change your filter class tag value in web.xml to <filter-class> org.apache.struts2.dispatcher.filter.Struts

Struts2 之 Validation 拦截器 基于XML配置方式实现(验证框架)

基于XML配置方式实现输入校验 I:定义Action *  要继承ActionSupport或者实现Validateable接口: II:配置struts_validate.xml文件 *  验证出错转向的页面                struts.xml配置<result name=“input”>/validate/loginxml.jsp</result>                  其中input转向是在action中已经定义好的. III:配置验证的xml文件

转载 - Struts2基于XML配置方式实现对action的所有方法进行输入校验

出处:http://www.cnblogs.com/Laupaul/archive/2012/03/15/2398360.html 使用基于XML配置方式实现输入校验时,Action也需要继承ActionSupport,并且提供校验文件,校验文件和action类放在同一个包下,文件的取名格式为:ActionClassName-validation.xml.ActionClassName为action的简单类名,-validation为固定写法.如果Action类为cn.validate.acti