struts2.1+hibernate 3.2+spring 2.5 整合

上传人:第*** 文档编号:34037964 上传时间:2018-02-20 格式:DOC 页数:6 大小:32KB
返回 下载 相关 举报
struts2.1+hibernate 3.2+spring 2.5 整合_第1页
第1页 / 共6页
struts2.1+hibernate 3.2+spring 2.5 整合_第2页
第2页 / 共6页
struts2.1+hibernate 3.2+spring 2.5 整合_第3页
第3页 / 共6页
struts2.1+hibernate 3.2+spring 2.5 整合_第4页
第4页 / 共6页
struts2.1+hibernate 3.2+spring 2.5 整合_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《struts2.1+hibernate 3.2+spring 2.5 整合》由会员分享,可在线阅读,更多相关《struts2.1+hibernate 3.2+spring 2.5 整合(6页珍藏版)》请在金锄头文库上搜索。

1、struts2.1+hibernate 3.2+spring 2.5 整合文章分类: Java 编程 在 MyEclipse 中新建一个项目,基于 j2ee5,按以下步骤: 1、类库: Struts:Commons-logging-x.x.x.jar、freemarker-x.x.x.jar、ognl-x.x.x.jar、xwork-x.x.x.jar、struts-2-core-x.x.x.jar、struts2-spring-plugin-x.x.x.jar Hibernate:Hibernate3.2 Core Libraries、Hibernate 3.2 Annotations &

2、Entity Manager(删除 asm.jar、asm-attrs.jar、cglib-x.x.x.jar) Spring:Spring 2.5 Aop Libraries、 Spring 2.5 Core Libraries、 Spring 2.5 Persistence Core Libraries、 Spring 2.5 Web Libraries Database pool: commons-pool.jar、commons-dbcp.jar 或者 c3p0-x.x.x.jar Database driver: mysql-connector-java-x.x.x.jar 2、we

3、b.xml 添加以下内容: contextConfigLocation /WEB-INF/applicationContext.xml org.springframework.web.context.ContextLoaderListener lazyLoadingFilter org.springframework.orm.hibernate3.support.OpenSessionInViewFilter lazyLoadingFilter *.action characterEncoding org.springframework.web.filter.CharacterEncoding

4、Filter characterEncoding /* actionContextCleanUp org.apache.struts2.dispatcher.ActionContextCleanUp actionContextCleanUp /* struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* 3、applicationContext.xml 及 jdbc.properties 在/WEB-INF 下新建 applicationContext.xml 及 jdbc.properties,内容如下: classp

5、ath:/com/test/domain/hbm/ org.hibernate.dialect.MySQLDialect true true jdbc.properties 的内容如下: jdbc.driverClassName=org.gjt.mm.mysql.Driver jdbc.url=jdbc:mysql:/localhost:3306/testssh jdbc.username=root jdbc.password= 4、src 下添加login4j.properties、messageResource.properties、struts.properties、struts.xml

6、 其中 struts.properties 的内容可以从 struts2-core-x.x.x.jar 的 org.apache.struts2下的 default.properties 下拷过来,修改以下几项 struts.locale=zh_CN struts.devMode = true #开发时高为 true 可以在调试时打印出更多信息,部署时设为false struts.custom.i18n.resources=messageResource #国际化文件为messageResource.properties 其他采用默认即可 struts.xml 的模板如下:(可直接从 stru

7、ts2-core-x.x.x.jar 根目录下拷 struts-default.xml 的文档声明) /success.jsp /index.jsp /error.jsp log4j.properties 内容如下:(只定义了输出 Debug 或以上级别信息到控制台) #1 区 # Use two appenders, one to log to console, another to log to a file log4j.rootLogger = debug, stdout #2 区 #Print only messages of priority WARN or higher for y

8、our category #log4j.logger.TestLog4j= , R #log4j.logger.TestLog4j.TestLog4j2=WARN #3 区 # First appender writes to console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the callers file name and line number. log4

9、j.appender.stdout.layout.ConversionPattern=%5p %t (%F:%L) - %m%n #4 区 # Second appender writes to a file #log4j.appender.R=org.apache.log4j.RollingFileAppender #log4j.appender.R.File=F:nepalonclassesTestLog4jexample.log # Control the maximum log file size #log4j.appender.R.MaxFileSize=100KB # Archiv

10、e log files (one backup file here) #log4j.appender.R.MaxBackupIndex=1 #log4j.appender.R.layout=org.apache.log4j.PatternLayout #log4j.appender.R.layout.ConversionPattern=%dyyyy-MM-dd hh:mm:ss:%p %t %c - %m%n 5、src 下的 com.test.domain.hbm 存放 hibernate 的表对象映射文件,如 User.hbm.xml,内容如下: 类的 Dao 操作继承 Spring 的 HibernateDaoSupport,并使用 getHibernateTemplate()方法取得 HibernateTemplate 对象进行各种增删改查操作。 6、Struts2 的 Xwork 验证框架配置文件,如 LoginAction-validate.xml(ActionName-validation.xml),与相应 Action 放在同个目录下,在 Jsp 页面的标签加上validate=true进行前台较验。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号