Struts2.x+Spring3.x+Hibernate4.x 整合(二)Struts+Spring 整合
来源:互联网 发布:苹果蜂窝数据快捷键 编辑:程序博客网 时间:2024/05/05 04:41
接上篇文章(Struts2.x+Spring3.x+Hibernate4.x 整合(一)Struts环境搭建)中的代码,向项目中整合Spring3.0.0框架。
注:项目源码附在文章下方。
1、下载Spring
到官方网站下载Spring3.0框架, 这里我已压缩一份:http://download.csdn.net/detail/xz2001/4844494。
另外, 还需要下载两个包:com.springsource.org.apache.commons.logging-1.1.1.jar 和 struts2-spring-plugin-2.3.7.jar,地址在:http://download.csdn.net/detail/xz2001/4844534
最后lib目录包含如下jar包:
2、修改web.xml配置文件,增加spring配置,修改后内容如下:
<?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>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
3、在WEB-INF目录中增加applicationContext.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="enterService" class="com.manage.enter.service.impl.EnterServiceImpl"></bean>
<bean id="enterAction" class="com.manage.enter.action.EnterAction">
<property name="service" ref="enterService"></property>
</bean>
</beans>
4、修改struts配置文件,修改后内容如下:
<?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>
<!-- 定义请求后缀 -->
<constant name="struts.action.extension" value="do,action" />
<!-- 启用动态调用方法 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 开发环境下使用,这样可以打印出更详细的错误信息 -->
<constant name="struts.devMode" value="false" />
<package name="manageEnter" namespace="/manage" extends="struts-default">
<action name="enter" class="enterAction">
<result name="login">/manage/enter/login.jsp</result>
<result name="success">/manage/enter/success.jsp</result>
<result name="error">/manage/enter/error.jsp</result>
</action>
</package>
</struts>
5、修改Action文件,为spring注入准备:
package com.manage.enter.action;
import com.manage.enter.service.EnterService;
import com.manage.enter.service.impl.EnterServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
public class EnterAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private EnterService service;
private String username;
private String password;
public EnterService getService() {
return service;
}
public void setService(EnterService service) {
this.service = service;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() throws Exception {
return "login";
}
public String login() throws Exception {
service = new EnterServiceImpl();
return service.load(this.username, this.password) ? "success" : "error";
}
}
6、测试访问
启动Tomcat,访问:http://localhost:8080/ssh/manage/enter.do
最后附上完成后的代码:http://download.csdn.net/detail/xz2001/4844476
- Struts2.x+Spring3.x+Hibernate4.x 整合(二)Struts+Spring 整合
- Struts2.x+Spring3.x+Hibernate4.x 整合(七)整合struts RESTful
- Struts2.x+Spring3.x+Hibernate4.x 整合(一)Struts环境搭建
- Struts2.x+Spring3.x+Hibernate4.x 整合(五)Struts 升级到 2.3.15.3
- Struts2.x+Spring3.x+Hibernate4.x 整合(六)整合log4j日志组件
- Struts1.x spring3 hibernate4 初步整合
- Spring3.x整合Struts2.3.x
- Spring4.x+Hibernate4.x整合
- Struts2.x、Spring3.x、Hibernate3.x整合开发
- struts 1.x spring 整合
- 整合SSH框架 (Struts2.x+Spring3.x+hibernate3.x+oracle)
- Spring4.x+Struts2.x整合
- Mybatis3.2和Spring3.x整合----Mybtis3.x+Spring3.x
- struts2+spring3+hibernate4整合
- spring3+Hibernate4+struts2整合
- MyBatis3.x和Spring3.x的整合
- Struts2+Spring3+Hibernate4整合之Spring配置文件
- Spring 与 Struts2.x的整合
- centos linux 下的jdk安装 jdk-6u26-linux-x64.bin
- Hibernate关联关系映射实例速查
- 摘自《编写高质量代码:改善Java程序的151个建议》第十一章 开源世界
- DOS中切换盘符(直接CD不行)
- IAR与GCC支持浮点数的printf, sprintf格式化
- Struts2.x+Spring3.x+Hibernate4.x 整合(二)Struts+Spring 整合
- 调用android系统相机拍照并保存
- 中国城市健康调查:三成白领性生活一月不到1次
- 马子跃---传奇 天籁
- 解决eclipse-helios中Errors running builder JavaScript Validator的问题(转)
- Instagram创始人Krieger谈产品设计的八条原则
- OpenGL学习笔记(三)
- MyEclipse10安装插件的几种方法
- Oracle数据库中NOLOGGING和FORCE LOGGING的理解