当前位置: 首页 > 编程日记 > 正文

Struts2+spring+jdbc 以xml配置形式整合

今天做作业,练习一下Struts2+spring+jdbc 以xml配置形式整合

整合步骤:


工程结构图:


重要配置文件

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"

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_2_5.xsd">

<display-name></display-name>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

<listener>

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

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring/applicationContext.xml</param-value>

</context-param>

<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>/*</url-pattern>

</filter-mapping>

</web-app>

 

其中spring通过监听器整合,struts2通过过滤器整合。

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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/context

           http://www.springframework.org/schema/context/spring-context-2.5.xsd

           http://www.springframework.org/schema/tx 

           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<import resource="applicationContext-db.xml" />

<import resource="applicationContext-ordertable.xml" />

<import resource="applicationContext-customer.xml" />

</beans>

applicationContext-db.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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/context

           http://www.springframework.org/schema/context/spring-context-2.5.xsd

           http://www.springframework.org/schema/tx 

           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!--     用dbcp配置

 产生dataSource

     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<value>classpath:jdbc/jdbc_dbcp.properties</value>

</property>

 </bean>

     <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">

<property name="driverClassName" value="${jdbc.driverClassName}" />

<property name="url" value="${jdbc.url}" />

<property name="username" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />

</bean>

-->

<!-- 产生dataSource  用c3p0配置-->

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<value>classpath:jdbc/jdbc_c3p0.properties</value>

</property>

</bean>

<bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="driverClass" value="${jdbc_c3p0.driverClass}" />

<property name="jdbcUrl" value="${jdbc_c3p0.driverClass.jdbcUrl}" />

<property name="user" value="${jdbc_c3p0.user}" />

<property name="password" value="${jdbc_c3p0.password}" />

</bean>

<!-- 

声明事务通知 

id事务标识 transaction-manager 

-->

<!-- 事务管理器 -->

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource">

<ref bean="dataSource"/>

</property>

</bean>

<!-- 声明目标方法中哪些方法需要事务,哪些不需要事务 -->

<tx:advice id="tx" transaction-manager="transactionManager">

<tx:attributes>

<!-- 

name 限定方法的名称            

isolation 隔离机制 

propagation传播机制

ready-only 只读

 -->

<tx:method name="save*" isolation="DEFAULT" propagation="REQUIRED" read-only="false" />

</tx:attributes>

</tx:advice>

<!-- spring框架做的事情 -->

<aop:config>

<aop:pointcut expression="execution(* lr.service.impl.CustomerServiceImpl.*(..))" id="perform" />

<aop:advisor advice-ref="tx" pointcut-ref="perform"/>

</aop:config>

</beans>

applicationContext-ordertable.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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/context

           http://www.springframework.org/schema/context/spring-context-2.5.xsd

           http://www.springframework.org/schema/tx 

           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="ordertableDao" class="lr.dao.impl.OrdertableDaoImpl">

<property name="dataSource">

<ref bean="dataSource"/>

</property>

</bean>

<bean id="ordertableService" class="lr.service.impl.OrdertableServiceImpl">

<property name="ordertableDao">

<ref bean="ordertableDao"/>

</property>

<property name="customerDao">

<ref bean="customerDao"/>

</property>

</bean>

<bean id="ordertableAction" class="lr.action.OrdertableAction">

<property name="ordertableService">

<ref bean="ordertableService"/>

</property>

</bean>

</beans>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"

"http://struts.apache.org/dtds/struts-2.1.7.dtd">

<struts>

<!-- 配置文件改了以后不用重新启动 -->

<constant name="struts.devMode" value="true"/>

<!-- 把struts的请求委托给spring管理,

        作用:创建Action实例的过程由spring处理,其他的还是有struts2自己处理 -->

<constant name="struts.objectFactory" value="spring" />

<include file="struts2/struts-ordertable.xml"></include>

<include file="struts2/struts-customer.xml"></include>

</struts>

struts-customer.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"

"http://struts.apache.org/dtds/struts-2.1.7.dtd">

<struts>

<package name="customer" extends="struts-default" namespace="/">

<action name="customerAction_*" method="{1}" class="customerAction">

<result name="success">/savecustomer.jsp</result>

</action>

</package>

</struts>


所需jar包下载

http://download.csdn.net/detail/u012814506/6709269

工程下载

http://download.csdn.net/detail/u012814506/6709313





相关文章:

我和你不了的故事

我和你不了的故事——代腾飞 2006年12月11日 于成都你无言告别而消失得无影无踪我的世界只留下了你昔日的背影从此你我相隔在不远不近的时空里然而我却失去了你所有的联系你带走的是我们在一起的欢歌笑语为我留下的却是思念的苦楚和美妙而难忘的回忆不知此时的你是否偶尔能把…

前后端分离的探索(四)

文桥&#xff0c;13级机械电子工程系&#xff0c;大四学生。在LSGO软件技术团队负责前端部分&#xff0c;本图文是介绍目前流行的前后端分离技术的第四篇&#xff08;一共六篇&#xff09;&#xff0c;希望大家能够对这块有所了解。

《Adobe Fireworks CS5中文版经典教程》——导读

前言Adobe Fireworks CS5是一款专业级图像处理应用程序&#xff0c;融矢量和位图处理功能于一身。之所以采取独特的图像处理方法&#xff0c;是由于Fireworks旨在让用户能够创建和处理屏幕图形&#xff0c;以供Web或诸如移动应用程序和Adobe Flash等基于屏幕的工具使用。Firewo…

使用wsimport生成本地调用代码

使用wsimport生成本地调用的步骤 wsimport是jdk自带的,可以根据wsdl文档生成客户端调用代码的工具. wsimport.exe位于JAVA_HOME\bin目录下. 常用参数为: -d<目录> - 将生成.class文件。默认参数。 -s<目录> - 将生成.java文件。 -p<生成的新包名> -将生成的…

单片机练习-RC-5红外遥控器程序及简单制造DIY PC遥控器

本程序采用的芯片为SAA3010, 参考资料有:1. 常用红外遥控接收头引脚图解2. 红外遥控编码资料3. RC-5红外遥控程序 4. GIRDER中文教程与电脑遥控器制作资料 5. Girder网站 (一个需要钱买的遥控)6. 再度出击&#xff0c;20元打造经典PC遥控器&#xff01;7. SAA3010 DataSheet这次…

《iOS9开发快速入门》——导读

本节书摘来自异步社区《iOS9开发快速入门》一书中的目录&#xff0c;作者 刘丽霞 , 邱晓华&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看 目 录前 言 第1章 iOS 9开发概述 1.1 iOS 9新特性 1.2 构建开发环境—Xcode 7.0 1.3 编写第一个iOS 9应用 1.4 小…

C#语言与面向对象技术(4)

本图文主要掌握以下问题&#xff1a; 1. 为什么要引入属性的概念&#xff1f; 2. 属性的get与set方法是怎样定义的&#xff1f; 3. 什么是索引器&#xff1f; 4. 索引器是如何实现的&#xff1f;

使用wsdl2java命令生成webservice本地调用代码

使用wsdl2java命令生成webservice本地调用代码 如果没有设置环境变量&#xff0c;就要先进入cxf的bin目录 例子&#xff1a; wsdl2java -d . http://localhost:7890/hello?wsdl 它包含以下参数&#xff1a; &#xff0d;d参数&#xff0c;指定代码生成的目录。 &#xff0d…

js表单验证大全

js验证表单大全1. 长度限制<script>function test() {if(document.a.b.value.length>50){alert("不能超过50个字符&#xff01;");document.a.b.focus();return false;}}</script><form namea οnsubmit"return test()"><textarea…

《为iPad而设计:打造畅销App》——大胆创意

本节书摘来自异步社区《为iPad而设计&#xff1a;打造畅销App》一书中的大胆创意作者【英】Chris Stevens&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看 大胆创意为iPad而设计&#xff1a;打造畅销App其他的应用开发者都在做什么呢&#xff1f;或许应该在应…

Matlab与线性代数 -- 对数化间隔向量

这段时间有同学给我后台留言&#xff0c;希望能够推送与Matlab相关的内容&#xff0c;本学期该微信号承担了数理系信息教研室线性代数课程内容推送和通知的任务&#xff0c;想来想去&#xff0c;就以此为契机&#xff0c;把Matlab和线性代数的内容结合起来吧&#xff0c;希望对…

ContentProvider访问问题

问题解决一&#xff1a; 写了一个类&#xff0c;实现了ContentProvider&#xff0c;在清单文件中也注册了。 <provider android:name".provider.MyProvider" android:authorities"mytest" /> 但是访问的时候出现异常&#xff1a; j…

《C++面向对象高效编程(第2版)》——3.11 类名、成员函数名、参数类型和文档...

本节书摘来自异步社区出版社《C面向对象高效编程&#xff08;第2版&#xff09;》一书中的第3章&#xff0c;第3.11节&#xff0c;作者&#xff1a; 【美】Kayshav Dattatri&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看。 3.11 类名、成员函数名、参数类型…

一个GDIPlus的Bug -- OutofMemory异常

今天发现 framework2.0中的一个GDIPlus的Bug: 在Form的OnPaint事件里面写如下代码&#xff1a; private void Form1_Paint(object sender, PaintEventArgs e) { Pen p new Pen(Color.Red); p.Width 1; p.DashStyle DashStyl…

前后端分离的探索(五)

文桥&#xff0c;13级机械工程系&#xff0c;机械电子工程专业&#xff0c;大四学生。在LSGO软件技术团队负责前端部分&#xff0c;本图文是介绍目前流行的前后端分离技术的第五篇&#xff08;一共六篇&#xff09;&#xff0c;希望大家能够对这块有所了解。

从一道面试题分析Thread.interrupt方法

阿里面试题&#xff1a; public class TestThread {public static void main(String[] args) {Thread t1 new Thread() {Overridepublic void run() {try {int i 0;while (i < 100000000) {// nothing}System.out.println("A1");} catch (Exception e) {System.…

对联广告,带关闭,可以移动

在网页中加入以下代码 两个图的&#xff0c;一个是关闭用到的&#xff0c;一个是广告图 <script languageJavaScript src"js/scroll.js"></script> js代码如下&#xff1a; suspendcode"<DIV idlovexin1 styleZ-INDEX: 10; LEFT: 6px; POSITION…

u一点·料:阿里巴巴1688ued体验设计践行之路. 导读

U一点料 阿里巴巴1688UED体验设计践行之路 阿里巴巴1688用户体验部著 前言 既赶路&#xff0c;也感受路 文 / 汪方进 用户体验设计师作为一个职能岗位&#xff0c;在国内互联网公司中存在已有十几年的时间了&#xff0c;早期的互联网公司设计师大都是无所不能的多面手&#xff…

Matlab与线性代数 -- 显示格式的设置

打磨一项技能最需要的就是耐心&#xff0c;我们知道做一件事情不会一蹴而就&#xff0c;需要长时间的积累。关于Matlab的打磨会持续很长的时间&#xff0c;每天学习一个知识点&#xff0c;一年下来就不得了。要有耐心&#xff0c;要有耐心&#xff0c;跟着小编每天花5分钟的时间…

java初始化顺序

java初始化顺序

值得收藏的经典网页代码(1)

1. 将彻底屏蔽鼠标右键,无右键菜单 <body οncοntextmenu"event.returnfalse"> 也可以用于网页中Table框架中&#xff1a;<table border οncοntextmenureturn(false)><td>no</table> 2.取消选取、防止复制 <body onselectstart"r…

五款漂亮的 GNOME 3.4 主题-PPA

国外著名开源网站WebUpd8已经把这五款漂亮的Gnome 3.4 的主题制作了PPA&#xff0c;可使用命令轻松实现安装。先来看看这几款主题的截图&#xff1a; adwaita-x-dark Adwaita X dark adwaita-x-light Adwaita X light evolve-gtk3 Evolve theme-ambiance-precise Ambiance-Prec…

Matlab与线性代数 -- 矩阵的加法与减法

打磨一项技能最需要的就是耐心&#xff0c;我们知道做一件事情不会一蹴而就&#xff0c;需要长时间的积累。关于Matlab的打磨会持续很长的时间&#xff0c;每天学习一个知识点&#xff0c;一年下来就不得了。要有耐心&#xff0c;要有耐心&#xff0c;跟着我们每天花5分钟的时间…

备考ocjp有感

看网上好多评论&#xff0c;说什么ocjp的证书很水&#xff0c;复习个一两天&#xff0c;背背题库就能过了。看了之后&#xff0c;有一些感想。 首先&#xff0c;有证书不代表什么&#xff0c;不能说你获得的什么证书&#xff0c;就一定有怎样的能力&#xff0c;有证书不代表什…

买了《精通spring 2.0》

刚才去书店选书&#xff0c;对比了好几本&#xff0c;最后选了这一本。听说第一版有些问题&#xff0c;不过感觉这一版本还可以。理论和实践都有所兼顾。书中的例子是spring自带的例子。转载于:https://www.cnblogs.com/chenge/archive/2007/06/06/774212.html

探索“小数”在计算机中的存储

本文介绍了小数在计算机中的存储方式&#xff0c;第一种为定点方式&#xff0c;这种方式很少遇到&#xff0c;但在Matlab中有涉及&#xff0c;见图文《Matlab与线性代数–显示格式的设置》。第二种为浮点方式&#xff0c;一个浮点数由阶码和尾数构成&#xff0c;一旦明白其中的…

《ELK Stack权威指南(第2版)》一3.8 Docker日志

本节书摘来自华章出版社《ELK Stack权威指南&#xff08;第2版&#xff09;》一书中的第3章&#xff0c;第3.8节&#xff0c;作者 饶琛琳 更多章节内容可以访问云栖社区“华章计算机”公众号查看。 3.8 Docker日志 Docker是目前大规模互联网基础架构解决方案中最热门的技术。…

为什么匿名内部类参数必须为final类型

转自&#xff1a;http://ldzyz007.iteye.com/blog/844380 基础语法&#xff1a;如果定义一个匿名内部类&#xff0c;并且希望它使用一个在其外部定的对象&#xff0c;那么编译器会要求其参数引用是final的。 1.匿名内部类肯定是局部内部类(在一个方法里面定义的内部类)&…

开始升级我的工作流系统

终于做完了自定义工作流审批系统的第一个版本&#xff0c;可以说是熬完的&#xff0c;因为真的费了不少力气。不过也慢慢发现设计和实现中的很多问题&#xff0c;便想把它改进一下&#xff0c;改为用.net2.0和sql server2005开发&#xff0c;并想遵从一定的xpdl规范来定义流程。…

《Python和Pygame游戏开发指南》——2.16 pygame.display.update()函数

本节书摘来自异步社区《Python和Pygame游戏开发指南》一书中的第2章&#xff0c;第2.16节&#xff0c;作者[美]Al Sweigart&#xff08;斯维加特&#xff09;&#xff0c; 李强 译&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看。 2.16 pygame.display.upda…