首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

spring跟struts2整合入门

2012-08-25 
spring和struts2整合入门?下面描述的内容是spring整合到struts2中的学习笔记?1、导入如下的jar包org.spring

spring和struts2整合入门

?

下面描述的内容是spring整合到struts2中的学习笔记

?

1、导入如下的jar包

org.springframework.core-3.0.1.RELEASE-A.jar

org.springframework.beans-3.0.1.RELEASE-A.jar

org.springframework.context-3.0.1.RELEASE-A.jar。

org.springframework.context.support-3.0.1.RELEASE-A.jar

org.springframework.asm-3.0.1.RELEASE-A.jar

org.springframework.expression-3.0.1.RELEASE-A.jar

另外还要添加Struts软件包里的:

commons-logging-1.0.4.jar

struts2-spring-plugin-2.1.8.1.jar(这个jar包是让spring和struts关联的重要工具)

?

2、在web.xml文件中配置如下信息

<listener>

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

</listener>

?

3、编写一个接口类UserService,然后创建一个类UserServiceImp继承前面定义的接口

?

4、在struts.xml文件中定义监听的action

?

备注:method="method"属性指明该action要执行encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"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.0.xsd"><bean id="userService" ref="userService"></property></bean></beans>

?

备注:bean中的id="addUserSpring"这个参数要和struts.xml文件中action的class="addUserSpring"联系起来,bean下面的property属性的name值应该和TestSpring中的属性对应上,然后spring给他一个已经new好的对象

?

?

?

?

?

?

?

热点排行