SSH 整合
--- ONE Goal, ONE Passion !
配置Struts2环境
1.导入Struts2的相关jar包
基础jar包13个:
- asm-3.3.jar
- asm-commons-3.3.jar
- asm-tree-3.3.jar
- commons-fileupload-1.3.jar
- commons-io-2.0.1.jar
- commons-lang3-3.1.jar
- freemarker-2.3.19.jar
- javassist-3.11.0.GA.jar
- log4j-api-2.0.jar
- log4j-core-2.0.jar
- ognl-3.0.6.jar
- struts2-core-2.3.7.jar
- xwork-core-2.3.7.jar
复制到WEB-INF/lib目录下.
2.添加log4j.properties文件
log4j.properties :
log4j.rootLogger=off,my
log4j.appender.my=org.apache.log4j.ConsoleAppender
log4j.appender.my.layout=org.apache.log4j.PatternLayout
log4j.appender.my.layout.ConversionPattern=%d %5p %c{1}:%L - %m%n
3.在web.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>
<!-- 配置Struts2的核心控制器-->
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.添加Struts2.xml的配置信息
struts.xml :
<?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.devMode" value="true" />
<!-- Add packages here -->
<package name="default" namespace="/" extends="struts-default">
</package>
</struts>
配置Spring环境
1.导入Spring的相关jar包
基础开发包14个:
- spring-aop-3.2.0.RELEASE.jar
- spring-aspects-3.2.0.RELEASE.jar
- spring-beans-3.2.0.RELEASE.jar
- spring-context-3.2.0.RELEASE.jar
- spring-core-3.2.0.RELEASE.jar
- spring-expression-3.2.0.RELEASE.jar
- spring-jdbc-3.2.0.RELEASE.jar
- spring-test-3.2.0.RELEASE.jar
- spring-tx-3.2.0.RELEASE.jar
- spring-web-3.2.0.RELEASE.jar
- commons-logging-1.1.3.jar
- com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar
- com.springsource.org.aopalliance-1.0.0.ja
- com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
2.配置applicationContext.xml
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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
">
</beans>
3.在web.xml中配置Spring的监听器
web.xml(部分) :
//监听器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
配置Hibernate环境
1.导入相关jar包
共12个jar,由于javassist-3.11.0.GA.jar已经在Struts2中添加过,不用添加.
- antlr-2.7.6.jar
- c3p0-0.9.1.2.jar
- commons-collections-3.1.jar
- dom4j-1.6.1.jar
- hibernate3.jar
- hibernate-jpa-2.0-api-1.0.1.Final.jar
- javassist-3.11.0.GA.jar
- jta-1.1.jar
- log4j-1.2.17.jar
- mysql-connector-java-5.0.4-bin.jar
- slf4j-api-1.6.1.jar
- slf4j-log4j12-1.7.2.jar
2.添加hibernate.cfg.xml配置文件
hibernate.cfg.xml :
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- 连接mysql数据库 -->
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/ssh</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!--mysql方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!--显示sql语句,以及格式化语句 -->
<property name="show_sql">true</property>
<property name="format_sql">false</property>
<mapping resource="添加自定义的hbm.xml文件"/>
</session-factory>
</hibernate-configuration>
现在基本配置已经完成了.一共有38个核心jar包.未完待续…