- 浏览: 1205019 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (718)
- HTML (13)
- JS基础 (23)
- JS应用 (40)
- AJAX (6)
- JSP相关 (12)
- JAVA基础 (52)
- JAVA应用 (74)
- APPLET (11)
- SWING\RCP (2)
- JAVA反射 (6)
- 设计模式 (26)
- 数据库设计 (20)
- Struts (35)
- Struts2 (12)
- Spring (22)
- Hibernate (45)
- Ibatis (18)
- mybatis (3)
- SSH (8)
- UML (5)
- WebService (3)
- XML (16)
- Log4j (7)
- WEB容器 (26)
- 数据结构 (36)
- Linux (34)
- Ruby on Rails (1)
- 其它技术 (27)
- IDE配置 (15)
- 项目实战 (2)
- Oracle (69)
- JAVA报表 (7)
- Android学习 (2)
- 博客链接 (1)
- 网络基础 (1)
- WEB集群 (1)
- .Net开发 (11)
- PB (4)
- 系统构建 (15)
最新评论
-
jnjeC:
牛逼啊哥们,讲得太好了
Maven仓库理解、如何引入本地包、Maven多种方式打可执行jar包 -
九尾狐的yi巴:
很好 感谢!
Itext中文处理(更新版) -
luweifeng1983:
有用的,重启一下嘛。
设置eclipse外部修改文件后自动刷新 -
Master-Gao:
设置了也不管用,怎么破呢?
设置eclipse外部修改文件后自动刷新 -
aigo_h:
锋子还有时间写博客,还是很闲哈!
Add directory entries问题
在集成方式一的基础上做改进:
第一种集成方案是在action中通过 WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext()); UserDao userDao = (UserDao)wac.getBean("userDao"); 来解决。 第二集成方案是通过spring注入,即把action配置在spring配置文件中,并把要用到的dao对象做为action bean的属性注入。 我们创建一个新的配置文件applicationContext-actions.xml <bean name="loginAction" class="com.lwf.spring.web.action.LoginAction"> <property name="userDao" ref="userDao"></property> </bean> 但这样还是使用struts的action,是单实例的,那么我们想使用spring的action怎么配置呢 有两种配置方法: 不管哪种配置方法首先应保持struts-config.xml中的path与applicationContext-actions.xml中的bean的name一致。 这是因为ActionServlet先是找struts-config.xml中的path,而path又是唯一的,那么要获得spring提供的action,只需在spring的配置中采用name与path一样即可。 第一种:使用代理的action类:DelegatingActionProxy 方法:使用spring的代理action,所以将struts-config中的action的type更改org.springframework.web.struts.DelegatingActionProxy 注意到spring源代码下的spring-framework-2.5.6.SEC01\dist\modules目录加入:spring-webmvc-struts.jar 如:<action path="/login" type="org.springframework.web.struts.DelegatingActionProxy" name="loginForm"> <forward name="success" path="/login_success.jsp"></forward> </action> 并且我们在spring配置中可以加入scope="prototype"即不通过单实例的方式创建,现在就可以解决struts单实例而引起的线程不安全问题。 第二种:使用spring的代理DelegatingRequestProcessor覆盖struts的RequestProcessor。 方法:为了在 struts-config.xml 文件中配置 DelegatingRequestProcessor,你需要重载 <controller> 元素的 “processorClass” 属性。 下面的几行应该放在 <action-mapping> 元素的后面。 <controller> <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/> </controller> 增加这些设置之后,不管你查询任何类型的 Action,Sping都自动在它的context配置文件中寻找。 实际上,你甚至不需要指定类型。下面两个代码片断都可以工作: <action path="/user" type="com.whatever.struts.UserAction"/> <action path="/user"/> 如果使用 Struts 的 modules 特性,则 bean 命名必须含有 module 的前缀。 举个例子,如果一个 Action 的定义为 <action path="/user"/>,而且它的 module 前缀为“admin”, 那么它应该对应名为 <bean name="/admin/user"/> 的 bean。 配置完成后我们再看看LoginAction中,直接使用userDao.add(name, pwd);不再需要通过WebApplicationContext获得dao再执行方法。
看看配置完后的代码:
action中代码:
package com.lwf.spring.web.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import com.lwf.spring.web.dao.UserDao; import com.lwf.spring.web.form.LoginForm; public class LoginAction extends Action { private UserDao userDao; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LoginForm loginForm = (LoginForm)form; String name = loginForm.getName(); String pwd = loginForm.getPassword(); userDao.add(name, pwd); return mapping.findForward("success"); } public void setUserDao(UserDao userDao) { this.userDao = userDao; } }
web.xml没有变
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="spring" version="2.5"> <display-name>TestWeb</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="loginForm" type="com.lwf.spring.web.form.LoginForm"></form-bean> </form-beans> <action-mappings> <action path="/loginjsp" forward="/login.jsp"></action> <action path="/login" type="org.springframework.web.struts.DelegatingActionProxy" name="loginForm"> <forward name="success" path="/login_success.jsp"></forward> </action> </action-mappings> <message-resources parameter="MessageResources"></message-resources> </struts-config>
新建的applicationContext-actions.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" > <bean name="/login" class="com.lwf.spring.web.action.LoginAction" scope="prototype"> <property name="userDao" ref="userDao"></property> </bean> </beans>
原来的applicationContext-beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" > <bean id="userDao" class="com.lwf.spring.web.dao.UserDaoImpl" ></bean> </beans>
其它文件不变。
具体代码见spring_struts_2
- spring_struts_2.rar (6.8 MB)
- 下载次数: 12
发表评论
-
spring 3 和mybatis 3集成,并用junit4进行测试
2011-11-04 14:01 1427转:spring 3 和mybatis 3集成,并用junit ... -
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource的解决方法
2011-11-03 16:17 2679用Myeclipse开发struts时,配置struts-co ... -
Strut2+Spring整合框架搭建
2011-11-02 22:19 1050参考:http://lukuijun.iteye.com/bl ... -
Spring+hibernate延迟加载报错解决办法之二
2010-06-29 17:28 1189在做删除操作的时候出现了org.springframework ... -
Spring+hibernate延迟加载报错解决办法之一
2010-06-29 17:25 1178我们在项目中一般都会使用Spring来管理Hibernate的 ... -
Spring项目中怎么配置log4j
2010-05-27 11:10 1552在spring项目中配置log4j http://blogg ... -
Spring与Struts集成方式三
2010-05-26 17:11 1122在集成方式一和二中我们是在web.xml中加入配置代码: & ... -
Spring与Struts集成方式一
2010-05-25 14:13 883我们在Struts中在action类中调用Model层组件进行 ... -
Hibernate编程式事务与Spring Aop的声明式事务(spring与hibernate集成)
2010-05-24 17:15 2747采用编程式事务 事务主要分为:编程式事务和声明式事务 ... -
修改Eclipse配置,使得在配置文件中完成自动完成功能。
2010-05-24 15:10 2265在Eclipse中引入spring的配置文件applicati ... -
Spring aop 基于schema的AOP支持及JoinPoint的使用、如何使用CGLIB代理
2010-05-24 14:52 4095基于schema的aop只是将配置写到配置文件中。 代 ... -
Spring AOP 概念理解及@AspectJ支持
2010-05-20 15:56 1555为了更好的理解Spring简介一文http://quicker ... -
Spirng AOP简介
2010-05-19 17:28 2258AOP 面向切面编程(AOP)通过提供另外一种思考程序结构的 ... -
Spring Bean中的自动装配——byType
2010-05-19 17:08 1165自动装配byType即通过查找类属性在配置文件中bean中定义 ... -
Spring Bean中的自动装配——byName
2010-05-19 16:34 3124自动装配(autowire)协作者 Spring IoC容器 ... -
Spring Bean的作用域:用Spring来解决Struts中Action的单实例问题
2010-05-19 10:47 1534我们知道在Struts中Action是从map中拿出来的,是单 ... -
Spring Bean定义的继承
2010-05-19 10:36 1307现有Bean2,Bean3,Bean4,Bean5 可观察到 ... -
Spring Set注入:基本类型、List、Map、Set、Array、Date类型注入
2010-05-18 15:58 11498Spring依赖注入有两种:构造器注入与Set注入 其中以S ... -
spring 初探
2010-05-17 16:53 1218Spring核心设计思想为IOC ... -
简单DAO层示例
2010-05-14 17:30 2048在使用spring架构之前,我们怎么设计自己的DAO层的呢? ...
相关推荐
NULL 博文链接:https://quicker.iteye.com/blog/674944
spring_struts集成spring_struts集成spring_struts集成
为了方便大家开发,特意制作了intellij环境下maven项目spring+struts集成空模板。直接导入intellij就可以用,模板下有个简单的小例子。对于学习spring+struts集成、以及希望快速开发的人来说都是不错的资源
三大框架集成及两两集成的jar包,spring集成hibernate的jar包以及spring集成struts2的jar包已经单独打包
spring 和struts2 集成所需要的jar包
struts spring集成 struts spring集成 struts spring集成
通过简单了实例 并提供代码 指导初学者学会spring和struts2的集成 并实现简单的登录功能
Spring集成struts以及hibernate jar包 所有的都在里面 需要的可以下载
NULL 博文链接:https://quicker.iteye.com/blog/676125
struts2 spring hibernate集成 介绍上传下载。。
Jpa+Spring+Struts集成步骤详解
Maven搭建spring_struts2_Hibernate项目源码,包括数据库,博客地址:http://blog.csdn.net/fengshizty/article/details/43794911
spring struts cxf 集成
SSH+Redis整合
SSH集成 Struts+spring+hibernate集成SSH集成 Struts+spring+hibernate集成
Spring2.5.5 struts2.1.6 ibatis2.3.4 Mysql5.1 利用IntelliJ IDEA(9) 集成 所有JAR包已经包含
集成Hibernate + Spring + Struts + Mybatis,jdk 32的版本
NULL 博文链接:https://whp0731.iteye.com/blog/358192
struts2入门教程及struts2集成spring。