struts2+hibernate+spring(1)

struts2+hibernate+spring

     文章主要讲述如何配置struts2+hibernate+spring,以及进行简单的应用开发

一 web.xml的配置以及简但说明:

web.xml如何配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
 xmlns=" http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
 <display-name>Struts Blank</display-name>
 
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-*.xml</param-value>
    </context-param>
   
 <filter>
  <filter-name>encodingFilter</filter-name>
  <filter-class>
   org.springframework.web.filter.CharacterEncodingFilter
  </filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
<!-- hibernate filter  -->
 <!-- <filter>  
      <filter-name>hibernateFilter</filter-name>  
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>   
  </filter>  
  <filter-mapping>  
      <filter-name>hibernateFilter</filter-name>  
      <url-pattern>/*</url-pattern>  
  </filter-mapping> 
   -->
 
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
 </filter>
 
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>
 
 <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
</web-app>

简单说明:

首先我们struts2中用到的action的创建工作是由spring 来完成的。spring提供一个监听器-org.springframework.web.context.ContextLoaderListener. 该监听其实现了ContextLoaderListener接口。servletContext的初始化事件以及销毁事件都会被其监听到!web.xml中定义了如下元素

(1)定义一个监听器

  <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

(2)监听器需要知道AppContext配置文件的位置

  于是context-param 中定义了一个参数:contextConfigLocation。spring通过参数contextConfigLocation 可以得到applicationContext配置文件的位置 

 
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-*.xml</param-value>
  </context-param>

在struts1.x中所有以 web.xml中定义了一个servelet----。所有以.do结为的请求都交与 该servlet处理。该servlet会根据根据用户请求,来调度不同的aciton进行处理。但是在struts2中,所有的请求都直接通过org.apache.struts2.dispatcher.FilterDispatcher来进行调度。

该类在初始化时创建一个默认的Dispatcher实例---org.apache.struts2.dispatcher.Dispatcher。该实例负责加载action类,并且调用用户配置的aciton方法(默认调用excute);方法向VALUESTACK中压入view试图(jsp界面)中所需要的值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值