SSH整合
SSH整合前应该先熟悉各个框架的单独使用,至少要了解各自的xml配置。
环境:struts-2.3.15.1,spring-3.2.4,hibernate-4.2.3,myeclipse10,JDK-1.6,Mysql
Jar包:
struts-2.3.15.1:
sturts2空项目下的所有jar包 | asm-3.3.jar |
asm-commons-3.3.jar | |
asm-tree-3.3.jar | |
commons-fileupload-1.2.2.jar | |
commons-io-2.0.1.jar | |
commons-lang3-3.1.jar | |
freemarker-2.3.19.jar | |
javassist-3.11.0.GA.jar | |
ognl-3.0.5.jar | |
struts2-core-2.3.4.1.jar | |
xwork-core-2.3.4.1.jar | |
其他 | struts2-spring-plugin-2.3.15.1 |
commons-logging-1.1.3 | |
aopalliance-1.0 | |
spring-3.2.4:
spring-aop-3.2.4.RELEASE.jar |
spring-beans-3.2.4.RELEASE.jar |
spring-context-3.2.4.RELEASE.jar |
spring-core-3.2.4.RELEASE.jar |
spring-expression-3.2.4.RELEASE.jar |
spring-jdbc-3.2.4.RELEASE.jar |
spring-orm-3.2.4.RELEASE.jar |
spring-tx-3.2.4.RELEASE.jar |
spring-web-3.2.4.RELEASE.jar |
hibernate-4.2.3:
lib-required下的所有jar包 |
c3p0-0.9.2.1.jar |
hibernate-c3p0-4.2.3.Final.jar |
hibernate-entitymanager-4.2.3.Final.jar |
1. 新建web项目
2. 以简单的登录验证为例
3. 建立login.jsp,login_success.jsp,login_error.jsp
4. 引入struts2
(1) l配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(2) src下的l配置
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="com.accp.action.LoginAction" method="login">
<result name="success"> /login_success.jsp </result>
<result name="error"> /login_error.jsp </result>
</action>
</package>
(3) 测试struts2是否能够通过
5. 引入spring
(1)配置l,添加listener
(1)配置l,添加listener
<listener>
<listener-class>org.t.ContextLoaderListener</listener-class>
</listener>
<!-- 告知spring config location 的存储位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>l</param-value>
</context-param>
(2)配置src下的l
将spring的l拷贝至src下,删除里面的配置项,只保留下面内容
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans.xsd"
>
</beans>
6. 引入hibernate
(1)配置l
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:jee="/schema/jee"
xmlns:tx="/schema/tx"
xmlns:aop="/schema/aop"
xmlns:p="/schema/p"
xmlns:util="/schema/util"
xmlns:tool="/schema/tool"
xmlns:context="/schema/context"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans.xsd
/schema/tx
/schema/tx/spring-tx.xsd
/schema/aop
/schema/aop/spring-aop.xsd
/schema/jee
/schema/jee/spring-jee.xsd
/schema/context
mysql下载jar包
/schema/context/spring-context.xsd
/schema/util
/schema/util/spring-util.xsd
/schema/tool
/schema/tool/spring-tool.xsd"
default-lazy-init="true" default-autowire="byName">
<!--spring jdbc配置数据源 Mysql-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="sql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="user" />
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论