SSH2整合 ssh2 框架 搭建 Office Word 版.docx

上传人:b****5 文档编号:6199108 上传时间:2023-01-04 格式:DOCX 页数:17 大小:147.63KB
下载 相关 举报
SSH2整合 ssh2 框架 搭建 Office Word 版.docx_第1页
第1页 / 共17页
SSH2整合 ssh2 框架 搭建 Office Word 版.docx_第2页
第2页 / 共17页
SSH2整合 ssh2 框架 搭建 Office Word 版.docx_第3页
第3页 / 共17页
SSH2整合 ssh2 框架 搭建 Office Word 版.docx_第4页
第4页 / 共17页
SSH2整合 ssh2 框架 搭建 Office Word 版.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

SSH2整合 ssh2 框架 搭建 Office Word 版.docx

《SSH2整合 ssh2 框架 搭建 Office Word 版.docx》由会员分享,可在线阅读,更多相关《SSH2整合 ssh2 框架 搭建 Office Word 版.docx(17页珍藏版)》请在冰豆网上搜索。

SSH2整合 ssh2 框架 搭建 Office Word 版.docx

SSH2整合ssh2框架搭建OfficeWord版

今天花了将近一天时间,看张冰老师的SSH2整合视频和自己手动整合SSH2,终于在晚上吃饭前整合成功了。

下面把自己第一次整合SSH2的过程记录下(以简单的用户注册为示例):

我这里所用的是struts-2.0.11.2,hibernate3.3.1,spring2.5.5不包版本之间可能有些包不同。

step1:

首先新建一个webproject项目,项目名为ssh2。

step2:

首先把ssh2整合的环境搭建好再来写代码。

把所需要的JAR包复制到WebRoot/WEB-INF/lib目录下

struts2所需要的包:

struts2-core-2.0.11.jar

xwork-2.0.4.jar

ognl-2.6.11.jar

freemarker-2.3.8.jar

commons-logging-1.0.4.jar

struts2-spring-plugin-2.0.11.2.jar(这个是struts2和spring整合的包)

hibernate3.3所需要的包:

hibernate3.jar(这个是hibernate的核心包)

以及hibernate3/lib目录下所有的包复制进来,lib目录下有三个目录required,optional,bytecode其中required是hibernate必须的包,防为防止漏包,我们把另二个目录下的所有包也复制进来

Spring2.5所需要的包:

spring-framework-2.5.5\dist目录下的spring.jar这个是spring的核心包

spring-framework-2.5.5\lib\aspectj\aspectjrt.jar

spring-framework-2.5.5\lib\aspectj\aspectjweaver.jar

spring-framework-2.5.5\lib\c3p0\c3p0-0.9.1.2.jar

spring-framework-2.5.5\lib\log4j\log4j-1.2.15.jar

spring-framework-2.5.5\lib\jakarta-commons\commons-dbcp.jar

spring-framework-2.5.5\lib\jakarta-commons\commons-pool.jar

spring-framework-2.5.5\lib\jakarta-commons\commons-collections.jar

spring-framework-2.5.5\lib\jakarta-commons\commons-logging.jar

spring-framework-2.5.5\lib\jakarta-commons\commons-collections.jar

最后别忘了把mysql的数据库驱动包引进来,这里用的是MYSQL数据库

不知道写的时候有没有写漏,可能有一些包有重复,造成有冲突,解决方法,可以先把tomcat停止,然后在进到webapps/工程所有目录下的WEB-INF/lib下查看所有引入进来的JAR包,看到有复制的就删掉,只留下最新的。

step3:

最后配置好的web.xml如下:

xmlversion="1.0"encoding="UTF-8"?

>

xmlns="

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

--配置Spring-->

contextConfigLocation

classpath:

application-*.xml

--配置Struts2-->

struts2

org.apache.struts2.dispatcher.FilterDispatcher

struts2

/*

--配置Spring的监听-->

org.springframework.web.context.ContextLoaderListener

--配置Spring的过滤器,解决乱码问题-->

encoding

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

encoding

/*

reg.jsp

src下struts.xml的最终代码如下:

xmlversion="1.0"encoding="UTF-8"?

>

DOCTYPEstrutsPUBLIC

"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"

"http:

//struts.apache.org/dtds/struts-2.0.dtd">

/regSuc.jsp

/regFail.jsp

在src下把hibernate相应的配置文件复制进来,hibernate.cfg.xml最终代码如下:

xmlversion='1.0'encoding='UTF-8'?

>

DOCTYPEhibernate-configurationPUBLIC

"-//Hibernate/HibernateConfigurationDTD3.0//EN"

"

--GeneratedbyMyEclipseHibernateTools.-->

update

true

把hibernate缓存的配置也复制进来ehcache.xml代码如下:

maxElementsInMemory="10000"

eternal="false"

timeToIdleSeconds="120"

timeToLiveSeconds="120"

overflowToDisk="true"

/>

maxElementsInMemory="10000"

eternal="false"

timeToIdleSeconds="300"

timeToLiveSeconds="600"

overflowToDisk="true"

/>

maxElementsInMemory="1000"

eternal="true"

timeToIdleSeconds="0"

timeToLiveSeconds="0"

overflowToDisk="false"

/>-->

把hibernate下的日志文件配置复制过来log4j.properties:

#ForJBoss:

AvoidtosetupLog4Joutside$JBOSS_HOME/server/default/deploy/log4j.xml!

#Forallotherservers:

CommentouttheLog4Jlistenerinweb.xmltoactivateLog4J.

log4j.rootLogger=INFO,stdout,logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d%p[%c]-%m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender

log4j.appender.logfile.File=${petstore.root}/WEB-INF/petstore.log

log4j.appender.logfile.MaxFileSize=512KB

#Keepthreebackupfiles.

log4j.appender.logfile.MaxBackupIndex=3

#Patterntooutput:

datepriority[category]-message

把spring的配置文件复制过来applicationContext.xml

这里我们把他改名为:

applicaton-beans.xml最后代码为:

xmlversion="1.0"encoding="UTF-8"?

>

//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"

xsi:

schemaLocation="

http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans-2.5.xsd

http:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-2.5.xsd

http:

//www.springframework.org/schema/txhttp:

//www.springframework.org/schema/tx/spring-tx-2.5.xsd">

scope="prototype">

再建立一个事务控制的application-transaction.xml代码最终如下:

xmlversion="1.0"encoding="UTF-8"?

>

//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"

xsi:

schemaLocation="

http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans-2.5.xsd

http:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-2.5.xsd

http:

//www.springframework.org/schema/txhttp:

//www.springframework.org/schema/tx/spring-tx-2.5.xsd">

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

classpath:

jdbc.properties

--配置数据源-->

class="mons.dbcp.BasicDataSource">

value="${jdbc.driverClassName}"/>

--配置SessionFactory-->

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

value="classpath:

hibernate.cfg.xml"/>

config>

advisorpointcut="execution(**..PetStoreFacade.*(..))"

advice-ref="txAdvice"/>

config>

adviceid="txAdvice"transaction-manager="txManager">

attributes>

methodname="insert*"/>

methodname="update*"/>

methodname="delete*"/>

methodname="modify*"/>

methodname="*"read-only="true"/>

attributes>

advice>

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

到此,所有的配置都整合好了,下面开始写代码

step4:

建立相应的jsp页面

注册页面reg.jsp代码如下:

<%@pagelanguage="java"pageEncoding="UTF-8"%>

<%

Stringpath=request.getContextPath();

StringbasePath=request.getScheme()+":

//"+request.getServerName()+":

"+request.getServerPort()+path+"/";

%>

DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">

">

SSH2用户注册

--

-->

用户注册

用户名:


密  码:


注册成功显示页面regSuc.jsp代码如下:

<%@pagelanguage="java"pageEncoding="UTF-8"%>

<%

Stringpath=request.getContextPath();

StringbasePath=request.getScheme()+":

//"+request.getServerName()+":

"+request.getServerPort()+path+"/";

%>

DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">

">

注册成功

--

-->

恭喜你注册成功了

注册失败regFail.jsp代码如下:

<%@pagelanguage="java"pageEncoding="UTF-8"%>

<%

Stringpath=request.getContextPath();

Stringbas

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1