- 浏览: 38590 次
- 性别:
- 来自: 大连
文章分类
最新评论
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="WebApp_ID" version="2.5"> <display-name>Spring Struts Hibernate</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml,classpath*:com/lpw/ssh/**/spring.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <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>*.do</url-pattern> </filter-mapping> </web-app>
configuration.properties
## database driver name. database.driver = com.mysql.jdbc.Driver ## database url address. database.url = jdbc:mysql://localhost:3306/d_spring_struts_hibernate ## database login username. database.username = root ## database login password. database.password = root
全局spring.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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:property-placeholder location="classpath:configuration.properties"/> </beans>
全局struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.objectFactory" value="spring"/> <constant name="struts.action.extension" value="do"/> <constant name="struts.multipart.maxSize" value="1073741824"/> <constant name="struts.devMode" value="true"/> <include file="com/lpw/ssh/item/index/struts.xml"/> </struts>
Hibernate spring.xm
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="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-3.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${database.driver}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}"/> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:hibernate.xml"/> </bean> </beans>
hibernate.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">false</property> <mapping class="com.lpw.ssh.item.index.IndexModel"/> </session-factory> </hibernate-configuration>
create.sql
DROP SCHEMA IF EXISTS d_spring_struts_hibernate; CREATE SCHEMA d_spring_struts_hibernate; USE d_spring_struts_hibernate; DROP TABLE IF EXISTS t_index; CREATE TABLE t_index ( c_id DECIMAL(20, 0) DEFAULT 0, c_name VARCHAR(255) DEFAULT '', CONSTRAINT pk_index_id PRIMARY KEY(c_id) );
IndexModel.java
package com.lpw.ssh.item.index; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; /** * @author leo */ @Entity(name = "com.lpw.ssh.item.index.IndexModel") @Table(name = "t_index") public class IndexModel implements Serializable { private static final long serialVersionUID = 3768248564175148141L; private long id; private String name; @Column(name = "c_id") @Id() @GeneratedValue(generator = "increment") @GenericGenerator(name = "increment", strategy = "increment") public long getId() { return id; } public void setId(long id) { this.id = id; } @Column(name = "c_name") public String getName() { return name; } public void setName(String name) { this.name = name; } }
IndexDao.java
package com.lpw.ssh.item.index; /** * @author leo */ public interface IndexDao { public void save(IndexModel index); }
DaoImpl.java
package com.lpw.ssh.item.index.impl; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import com.lpw.ssh.item.index.IndexDao; import com.lpw.ssh.item.index.IndexModel; /** * @author leo */ public class DaoImpl implements IndexDao { private SessionFactory sessionFactory; @Override public void save(IndexModel index) { Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); session.saveOrUpdate(index); transaction.commit(); session.close(); } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } }
IndexService.java
package com.lpw.ssh.item.index; /** * @author leo */ public interface IndexService { public void saveName(String name); public String sayHi(String name); }
ServiceImpl.java
package com.lpw.ssh.item.index.impl; import com.lpw.ssh.item.index.IndexDao; import com.lpw.ssh.item.index.IndexModel; import com.lpw.ssh.item.index.IndexService; /** * @author leo */ public class ServiceImpl implements IndexService { private IndexDao indexDao; @Override public void saveName(String name) { IndexModel index = new IndexModel(); index.setName(name); indexDao.save(index); } @Override public String sayHi(String name) { return "hello "+name; } public void setIndexDao(IndexDao indexDao) { this.indexDao = indexDao; } }
IndexAction.java
package com.lpw.ssh.item.index; /** * @author leo */ public class IndexAction { private String name; private IndexService indexService; public String execute() { indexService.saveName(name); return "success"; } public String getHi() { return "hi "+name; } public void setName(String name) { this.name = name; } public void setIndexService(IndexService indexService) { this.indexService = indexService; } }
index/spring.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="index.dao.target" class="com.lpw.ssh.item.index.impl.DaoImpl" scope="prototype"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="index.dao.source" class="org.springframework.aop.target.CommonsPoolTargetSource"> <property name="targetBeanName" value="index.dao.target"/> <property name="maxSize" value="25"/> </bean> <bean id="index.dao" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="targetSource" ref="index.dao.source"/> </bean> <bean id="index.service.target" class="com.lpw.ssh.item.index.impl.ServiceImpl" scope="prototype"> <property name="indexDao" ref="index.dao"/> </bean> <bean id="index.service.source" class="org.springframework.aop.target.CommonsPoolTargetSource"> <property name="targetBeanName" value="index.service.target"/> <property name="maxSize" value="25"/> </bean> <bean id="index.service" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="targetSource" ref="index.service.source"/> </bean> <bean id="index.action" class="com.lpw.ssh.item.index.IndexAction" scope="prototype"> <property name="indexService" ref="index.service"/> </bean> </beans>
index/struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="index" namespace="/" extends="struts-default"> <action name="index" class="index.action"> <result>index.ftl</result> </action> </package> </struts>
index.ftl
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Spring3.0+Struts2.1.8+Hibernate3.5</title> </head> <body> <h1>${hi}</h1> </body> </html>
相关推荐
spring3.0+struts2.1.8+hibernate3.2完整jar包 ,保证非常全,放心下载使用。请使用struts2.1.8,如果你已经在学习2.1.6版本,并且遇到类似xwork的异常,导致tomcat无法正常启动,可将struts2.1.8和xwork2.1.6两个包...
JQuery1.4.2+Struts2.1.8+JSON0.34+Spring2.5.6+Hibernate3.5+XFire1.2.6整合实例(已上传) 1、JSON0.34使用的是struts2附带的struts2-json-plugin-2.1.8.1.jar 2、db是mysql,名字为test,用户名root,密码空 3、...
【JBPM4.4+Hibernate3.5.4+Spring3.0.4+Struts2.1.8整合】的整个过程涉及到多个关键组件的集成,这些组件都是Java企业级开发中的重要部分。首先,JBPM(Business Process Management)是一个开源的工作流引擎,它...
本项目涉及的是Spring 2.5.6、Struts 2.1.8和Hibernate 3.3.2这三大流行Java企业级框架的集成。下面将详细介绍这三个框架及其集成的关键知识点。 首先,Spring框架(2.5.6版本)是一个轻量级的全面应用框架,它提供...
spring3.0.4 struts2.1.8 hibernate3.5.5 整合 所需要的jar文件(2) 由于文件稍大 给你第一个文件的链接 http://download.csdn.net/source/2647320
标题中的"spring2.5.6 +struts2.1.8+hiernate3.3.2(jar)"指的是一个集成开发环境,它包含了三个关键的Java Web框架:Spring 2.5.6、Struts 2.1.8和Hibernate 3.3.2。这些框架在Java应用开发中扮演着重要的角色,尤其...
spring3.0.4 struts2.1.8 hibernate3.5.5 整合 所需要的jar文件(1) 导入就能是使用了 不会有冲突. 前提是你的配置文件正确 由于文件太大 给你第二个文件的链接http://download.csdn.net/source/2647325
### 最新版本Struts2.1.8+Spring3.0+Hibernate3.3.2+DWR2.0.6配置详解 在本篇内容中,我们将详细探讨如何搭建一个基于Struts2.1.8、Spring3.0、Hibernate3.3.2以及DWR2.0.6的Web应用程序框架。这一组合被称为SSH+...
标题 "spring 3.0.4 + hibernate3.6 + mybatis3.0.4 + struts 2.1.8 + freemarker 整合" 描述了一个经典的Java Web开发集成框架,用于构建高效、可扩展的Web应用程序。这个组合在过去的几年里非常流行,因为它将多个...
Struts2.1.8+Hibernate3.3+Spring3.0是经典的Java Web开发框架组合,也被称为SSH(Struts2、Spring、Hibernate)。这个环境的搭建涉及到多个步骤,涵盖了MVC(Model-View-Controller)框架、持久化框架和依赖注入...
标题 "spring2.5.6+hibernate3.3.2+struts2.1.8" 提供了一个经典的Java Web开发技术栈,这个组合被称为S2SH(Spring、Struts2和Hibernate)。这个版本的集成对于初学者来说是一个很好的起点,因为它包含了三个主要的...
本文将详细介绍如何配置新版SSH+DWR框架,即Struts2.1.8、Spring3.0和Hibernate3.3.2与Direct Web Remoting (DWR) 2.0.6的集成。这个配置示例是基于目前最新的技术栈,旨在提供一个高效、稳定的开发环境。 首先,...
本版本全面更新了jar包,全部使用了当前最新版本的jar包,struct2.1.8 spring3 hibernate3.5,全面使用注解取代xm的l配置。 另外增加了一个ant构建脚本,支持使用hudson完成每日构建,持续集成,自动测试,代码规范...
Struts2.1.8+Spring2.5.6+Hibernate3.3.2是经典的Java Web开发框架组合,常被称为SSH。这三个框架协同工作,为开发者提供了强大的模型-视图-控制器(MVC)架构支持,使得企业级应用的开发更加高效和模块化。 Struts...
本版本全面更新了jar包,全部使用了当前最新版本的jar包,struct2.1.8 spring3 hibernate3.5,全面使用注解取代xm的l配置。 另外增加了一个ant构建脚本,支持使用hudson完成每日构建,持续集成,自动测试,代码规范...
Struts2.1.8、Hibernate3.5.6与Spring3.0是经典的Java企业级开发中的"散打框架"(S2SH)组合,它们的整合为开发者提供了强大的功能,支持MVC架构和持久层管理。在这个整合中,Struts2负责表现层的控制流程,Spring...
Struts2.1.8+Hibernate3.3+Spring3.0整合是一个常见的Java企业级应用开发模式,这种集成框架的使用旨在优化后端服务,提高开发效率,并提供灵活的数据持久化解决方案。以下是对这个集成知识点的详细说明: **Struts...