下载

2下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 Eclipse下SSH2框架搭建_详细

Eclipse下SSH2框架搭建_详细.doc

Eclipse下SSH2框架搭建_详细

carol貅
2012-09-09 0人阅读 举报 0 0 暂无简介

简介:本文档为《Eclipse下SSH2框架搭建_详细doc》,可适用于IT/计算机领域

一、Struts和Spring整合,创建一个OA工程、整合struts)导入strut的jar包:commonsloggingjar,freemarkerjar,ognljar,strutscorejar,xworkjar。暂时导入这些jar包到时候需要再倒入。)将strutsxml文件放置在OA工程的src目录下。)在webxml里面配置struts用到的核心过滤器。Xml代码<filter><filtername>struts<filtername><filterclass>orgapachestrutsdispatcherFilterDispatcher<filterclass><filter><filtermapping><filtername>struts<filtername><urlpattern>*<urlpattern><filtermapping>、整合spring)导入spring的jar包:springjar)将applicationContextxml文件放置在OA工程的WEBINF目录下。)在webxml里面配置spring用到的监听器。Xml代码<listener><listenerclass>orgspringframeworkwebcontextContextLoaderListener<listenerclass><listener>)添加strutsspring整合的插件:strutsspringpluginjar,如果不使用这个插件则需要在strutsxml里面配置:Xml代码<constantname="strutsobjectFactory"value="orgapachestrutsspringStrutsSpringObjectFactory">、测试struts和spring整合对不对写一个jsp页面loginjsp来测试:Html代码<pagelanguage="java"contentType="texthtmlcharset="pageEncoding=""><taglibprefix="s"uri="strutstags"><!DOCTYPEhtmlPUBLIC"WCDTDHTMLTransitionalEN""http:wwwworgTRhtmlloosedtd"><html><head><metahttpequiv="ContentType"content="texthtmlcharset="><title>Inserttitlehere<title><head><body><s:formaction="Login"method="post"><s:textfieldname="userName"label="userName"><s:textfield><s:passwordname="password"label="password"><s:password><s:submitlabel="submit"><s:submit><s:form><body><html>写一个LoginActionJava代码packagecomstrutsactionimportcomopensymphonyxworkActionSupportimportcomstrutsserviceLoginServicepublicclassLoginActionextendsActionSupport{privateLoginServiceloginServiceprivateStringuserNameprivateStringpasswordpublicvoidsetLoginService(LoginServiceloginService){thisloginService=loginService}publicStringgetUserName(){returnuserName}publicvoidsetUserName(StringuserName){thisuserName=userName}publicStringgetPassword(){returnpassword}publicvoidsetPassword(Stringpassword){thispassword=password}OverridepublicStringexecute()throwsException{if(loginServiceisLogin(userName,password))returnSUCCESSelsereturnINPUT}}写一个ServiceJava代码packagecomstrutsservicepublicinterfaceLoginService{booleanisLogin(StringuserName,Stringpassword)}写一个Service的实现Java代码packagecomstrutsserviceimplimportcomstrutsserviceLoginServicepublicclassLoginServiceImplimplementsLoginService{publicbooleanisLogin(StringuserName,Stringpassword){if("hello"equals(userName)"world"equals(password))returntrueelsereturnfalse}}在strutsxml里面配置:Xml代码<packagename="struts"extends="strutsdefault"><actionname="Login"class="loginAction"><resultname="success">resultjsp<result><resultname="input">loginjsp<result><action><package>在applicationContextxml里面配置:Xml代码<beanid="loginService"class="comstrutsserviceimplLoginServiceImpl"><bean><beanid="loginAction"class="comstrutsactionLoginAction"scope="prototype"><propertyname="loginService"ref="loginService"><property><bean>启动tomcat分别输入hello和world提交,结果为hello和world。说明struts和spring整合成功。StrutsSpring整合实现接下来继续整合Hibernate前面已经讲述了StrutsSpring整合这里我们接着整合Hibernate整合Hibernate)导入Hibernate的jar包:antlrjar,commonscollectionsjar,domjjar,javassistGAjar,jtajar,hibernatejar,slfjapijar,slfjlogjjar,logjjar。暂时导入这些jar包到时候需要再倒入。)将spring的配置文件applicationContext*xml文件放置在OA工程的src目录下,这里我们有三个:applicationContextactionxml,applicationContextbeansxml,applicationContextcommonxml)在webxml里面配置Xml代码<!whenapplicationserverstarted,loadingtheapplicationContext*xml><contextparam><paramname>contextConfigLoaction<paramname><paramvalue>classpath*:applicationContext*xml<paramvalue><contextparam><!integeratespring><listener><listenerclass>orgspringframeworkwebcontextContextLoaderListener<listenerclass><listener><!letspringmanagehibernate'ssession,thatwecanfocusbussinesslayer><filter><filtername>hibernateFilter<filtername><filterclass>orgspringframeworkormhibernatesupportOpenSessionInViewFilter<filterclass><filter><filtermapping><filtername>hibernateFilter<filtername><urlpattern>*action<urlpattern><filtermapping><!configratestrutscorefilter><filter><filtername>struts<filtername><filterclass>orgapachestrutsdispatcherFilterDispatcher<filterclass><filter><filtermapping><filtername>struts<filtername><urlpattern>*<urlpattern><filtermapping><!configuratewebcharacterencoding><filter><filtername>encodingFilter<filtername><filterclass>orgspringframeworkwebfilterCharacterEncodingFilter<filterclass><initparam><paramname>encoding<paramname><paramvalue><paramvalue><initparam><filter><filtermapping><filtername>encodingFilter<filtername><urlpattern>*<urlpattern><filtermapping>)spring里面有声明式事务它对hibernate做了封装在applicationContextcommonxml里面配置spring的声明式事务:Xml代码<!configuresessionFactory><beanid="sessionFactory"class="orgspringframeworkormhibernateLocalSessionFactoryBean"><propertyname="configLocation"><value>classpath:hibernatecfgxml<value><property><bean><!configuretransactionmanager><beanid="transactionManager"class="orgspringframeworkormhibernateHibernateTransactionManager"><propertyname="sessionFactory"><refbean="sessionFactory"><property><bean><!configuretransaction'spropagationalfeature><tx:adviceid="txAdvice"transactionmanager="transactionManager"><tx:attributes><tx:methodname="add*"propagation="REQUIRED"><tx:methodname="delete*"propagation="REQUIRED"><tx:methodname="modify*"propagation="REQUIRED"><tx:methodname="*"readonly="true"><tx:attributes><tx:advice><!configurewhichclass'swhichmethodtakepartintransaction><aop:config><aop:pointcutid="allManagerMethod"expression="execution(*comstrutsserver**())"><aop:advisorpointcutref="allManagerMethod"adviceref="txAdvice"><aop:config>用到了spring的aop,因此我们把spring的aop的jar包aspectjrtjar和aspectjweaverjar加入到lib目录。spring没有开发自己的aop的jar包它也是利用别人已经开发好的jar包aspectjrtjar和aspectjweaverjar。)测试StrutsSpringHibernate整合是否成功第一步:测试SpringHibernate整合是否成功写一个需要映射的值对象PersonJava代码packagecomoamodel***authorlukuijunhanqinetcom*hibernateclasstalbe="tperson"*publicclassPerson{***hibernateidgeneratorclass="native"*privateintid***hibernateproperty*privateStringname***hibernateproperty*privateStringsex***hibernateproperty*privateStringaddress***hibernateproperty*privateStringduty***hibernateproperty*privateStringphone***hibernateproperty*privateStringdescriptionpublicintgetId(){returnid}publicvoidsetId(intid){thisid=id}publicStringgetName(){returnname}publicvoidsetName(Stringname){thisname=name}publicStringgetSex(){returnsex}publicvoidsetSex(Stringsex){thissex=sex}publicStringgetAddress(){returnaddress}publicvoidsetAddress(Stringaddress){thisaddress=address}publicStringgetDuty(){returnduty}publicvoidsetDuty(Stringduty){thisduty=duty}publicStringgetPhone(){returnphone}publicvoidsetPhone(Stringphone){thisphone=phone}publicStringgetDescription(){returndescription}publicvoidsetDescription(Stringdescription){thisdescription=description}}运行ant生成Personhbmxml映射文件:Xml代码<xmlversion=""encoding=""><!DOCTYPEhibernatemappingPUBLIC"HibernateHibernateMappingDTDEN""http:hibernatesourceforgenethibernatemappingdtd"><hibernatemapping><classtable="tperson"name="comoamodelPerson"><idaccess="field"name="id"><generatorclass="native"><id><propertyname="name"access="field"><propertyname="sex"access="field"><propertyname="address"access="field"><propertyname="duty"access="field"><propertyname="phone"access="field"><propertyname="description"access="field"><class><hibernatemapping>运行ant生成hiberantecfgxml文件:Xml代码<xmlversion=""encoding=""><!DOCTYPEhibernateconfigurationPUBLIC"HibernateHibernateConfigurationDTDEN""http:hibernatesourceforgenethibernateconfigurationdtd"><hibernateconfiguration><sessionfactory><propertyname="hibernateconnectiondriverclass">commysqljdbcDriver<property><propertyname="hibernateconnectionurl">jdbc:mysql:localhost:oa<property><propertyname="hibernateconnectionusername">root<property><propertyname="hibernateconnectionpassword">hanqinet<property><propertyname="hibernatedialect">orghibernatedialectMySQLDialect<property><propertyname="hibernateshowsql">true<property><propertyname="hibernatehbmddlauto">update<property><mappingresource="comoamodelPersonhbmxml"><sessionfactory><hibernateconfiguration>接着启动Tomcat,启动完毕检查数据库里面新增加了表tpersonSpringHibernate整合成功第二步:测试StrutsSpring整合是否成功参考一、StrutsSpring整合测试成功完成这个两步成功说明我们的框架整合成功!

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/10

Eclipse下SSH2框架搭建_详细

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利