-【优秀文档资料】SSh框架搭建示例(打印版)_第1页
-【优秀文档资料】SSh框架搭建示例(打印版)_第2页
-【优秀文档资料】SSh框架搭建示例(打印版)_第3页
-【优秀文档资料】SSh框架搭建示例(打印版)_第4页
-【优秀文档资料】SSh框架搭建示例(打印版)_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ssh框架搭建说明搭建环境名称版本myeclipse5.5.1struts1.1hibernate3spring1.2tomcat6.0启动myeclipse环境,新建一个名为demossh的web工程,如卜图点击finish按钮以完成工程创建struts集成a) .为工程添加struts,右击工程文件,在弹出的右键菜单中选中myeclipse节点卞的add struts capabilities,这时即将弹出如下窗口struts config pth:struts specificstion:actionservlet name:url patternbase package for new

2、 classes:default application resources:com.yourcompany. strutsbrowsecom. yoxircompany. struts. appli cati onresourcesstruts support for myeclipse web projectenable project for struts developmentweb project:demosshwebroot folder:/webrootservlet specification: 2.4/web-inf/struts-config. xmlbrowse.ostr

3、uts 1.0 ©struts 1. 1 ostruts 1.2iactiondo (j: /do/*view libraries.cancel0install struts jars install struts tldsfim shb) .在base package for new classes栏内配置好相丿应的公司名称,点击finish按钮完成struts 的添加.c) .双击/web-inf/目录下的 struts-config.xml 件,然后在 struts-config.xml 的 design 视图 执彳亍一下操作,"右击-> newform,act

4、ion and jspn这时弹出一下界面> nevstruts 1.1 form declarationform impl:superclass:form type:new formbeanoxisting formbean odynamic formbeanorg. apache struts, action. actionformvcom. jb. arui. web. st ruts. form. logi nformoptional detailsform properties i methods jspproperties:us er name 一 j ava lang. s

5、tring password - j ava. 1 ang. string <html: text/>addremovenext >finishcancelcreate struts 1. 1 formbeand) 在use case栏内填入form bean的名称,如上图所示,在form properties选项卡屮添加两 个属性,分别为username和password,在jsp选项卡中指定要创建的jsp页面,如图struts 1.1 form declarationform impl:superclass:form type:g.'new formbeanc&#

6、39;existing formbeano' dynamic formbeanorg. apache struts. action. actionformvcom. jb. arui. web. struts. form. logirtformcreate struts 1. 1 fombeanoptional detailsform propertiesmethods0 create jsf form?new jsp path:/login. jsprext >fini shcancelkerf)、在forwards选项卡中添加页面跳转后的界面,如图ne< forvard

7、i iredirectbrowsename :path:i i context relativecloseg) 这里去掉 昶萇虽总他述前面的复选框,点击finish., struts能给我们自动填充某些代码.h) 这时,在webroot文件夹下新建一个success.jsp的页血,页血内容如下图:<body><hl>ohz yeah! struts搭建成功!</hl></body>然后修改com.jb.arui.wcb.struts.loginaction的execute方法为如下图所示的内容loginform loginform = (logi

8、nform) form;/ todo auto-generated method stub system out printin(loginform getusername();system out println(loginform getusername();return mapping.findforward(lsuccess)|;|i)启动tomcat服务器,新开浏览器并输入网址:http:/localhost:8080/dcmossh/loginisp测试 struts是否搭建成功hibernate的集成(釆用示例数据库pubs)a)、酋先将perties拷贝到sr

9、e冃录下b)、点击右上角的并单击myeclipsc database explore,在db browsers iftl板中执彳丁以下操作,“右击tncw”这是弹出以下窗口:c) 、单击 configure database driver 配直驱动,如图:preferences (filtered)typ© filtai" textdriversconfigured dtabase drivers:odbc bridge jjmicrosoft sql serverokcanceld) 这时点击new如下图所示> edit drivere)、在此界面配登数据库的连接骡

10、动,点击add jars即可增加数据库的直连驱动包,这里我们 书写 driver name:的名字为 microsoft sql server,点击 ok,回到 database profile 配置界而database profilef)存这里我们选择driver为:microsoft sql server,点击完成.g) .在工程卜面新建一个包名为coml.jb.arui.hibernate的包,用于存放hibernate的相关文件 为工程添加hibernate,右击工程文件,在弹岀的右键菜单中选屮myeclipse节点下的add hibernate capabilities,这时即将弹出

11、如f窗口hibernate support for myeclipseno jar/zip files contained in selected libraries.hibernate specifi cation: o1 hiberna2 ohibernate 3hiberna3.1select myeclipse/user librariesshow:0 myeclipse libraries i i user libraries3 hibernate 3.1 core libraries 一 <wyeclipse"library>_ hibernatg 3.1 a

12、dvanced suppert librari es - <jflyeclipselibrary>uiww and edit libraries;.jar library installationo add checked libraries to project buildpath:;:;library folder: /webroot/web-inf/libbrowsenext >finishcancelh) 在这里,我们使川hibernate3.1的版本,并在jar library installation面板屮选取copy checkedlirary jars此项,如

13、上图所示,单击next如下图:kev hibernate projecti)单击next:如卜图:j)在db profile栏内选取我们事先配置好的数据源my_sqlscrver_profhe,单击next,如下图k)此界面川于配置hibematesessionfactory的存放位置,单击browse,选取我们事先创建 的包 com.jb.arui.hibernate,我们把 hibernatesessionfactory 放在 com.jb.arui.hibernate 包内,单 击finish,这吋hibernate会自动帮我们生成某些代码增加hibernate映射文件1).打开 db

14、browser 面板右击 my_sq 1 fi 1 et 执行 “open another connection v 操作, 并依次打开节点,如下图所示localhgt sqlserverpr©filemy_sqlserver_profilea-+i-connectwd to my_sqlserver_profi1e a日game masmsdbnxt hwindpubs 鹽i人+自dbo+system tabletableh quthors discountsh employeejobsct pub_in£o 冏 publisherh roysched

15、sales1+ h a h 田b 七hshhhstorestitleauthortit “sviewprocedurefunctiontrigger閃 gues t破 il?forfrtation_schema豆目 system_function_schema t empdbtestdb zcglhl)、如上图所示,我们选取到数据库名为pubs下的jobs表,执行以下操作“右击 jobs->hibernate reverse engineering.n 这时将会出现以下界面:hibernate mapping and application generationgenerate hibe

16、rnate mapping and java classes from database explorer tablesgenerate hibernate mapping files and java classesjava src folder:java package:browsevj updatei i hibernate mapping file (. hbm .xml) for each database table hibernatg configuration with mapping file locatiori java object (pojo <> db t

17、able)i icreatg abstract classbrowse.base persisterit class:java data access object (dao) (hibernate 3 only)generate precise findby methodsdao type: ©basic dao ospring dao o珈i daocancelfinishn)单击browser,选取我们想要添加hibernate框架的项忖工程即dcmossh,并选取z前 所创建好的包文件,即com.jb.arui.hibernate,ft后配置好的界面如下:0)单击下一步:如下

18、图所示hibernate mapping and application generationconfigure type mapping det ailstype mapping:id generator:fini shcancelrev-eng settingsi generate basici i generaversi on and timestamp tagsjdbc typehibernat.lengthscaleprecisionnot-nullcustomized type mappings:< backnext >p)> 在 id generator:选取为

19、 native,在 next 如卜图jobs employee publishers pub_info ti ties roysched sales t i tl*u thor stores authors discountsh扇mm-®«-®m扇-m-m ©a-a-$-a-$-si-$-ffl-$-田< backfinishcancelhibernate mapping and application generationconfigure reverse engineering detailsgenerate artifacts for the

20、 following tables:select a table or column to configure mapping details0include referenced tables -b) 叼include referencing tab!esjmapping strategy when table in list (listedtable) references or is referred to by table not in list (unlistedtable)叼generate support for listedtable (fk)->unlistedtm电0

21、 genera ta suppor t for uni is tgdtgble (fk)>li s tedtmeq)、如上图配置好,点击finisho这时我们可以看到在com.jb.arui.hibernate已经增加了些配 置文件f)、到这里为止,我们已经把hibernate fr;架搭建好了接下来,我们测试hibernate是否能从数据库中查岀数据來s)、在工程中新建一个名为:com.jb.arui.dao,并在此包下面新建一个名为hibdao的类,书写如 下代码1314 public class hibdao extends basehibernatedaot15116- publ

22、ic list<jobs> findlll()17 session session = super.getsession();18 string query = from jobs"19 query r = session.createquery(query);山20list<jobs> job = r.list();121return job;22 2324 t)>新建一个com.jb.arui.tcst包,并在此包下创建一个测试类,名为tcsthibdao并基础 tcstcasc在测试类testhibdao书写如下代码1 package com.jb

23、.arui.test;23*com. jb arui . dao . hibdao;5 import junit.framework.testcase;66 public class testhibdao extends testcase 8i 9d /*|110 *测试hibernate的方法111 *112 *113 - pulilic void testfindall () 114 hibdao hib = new hibdao();血 15this.assertnotnull(hibfindall();|16 )|1718 19u)、执行以下操作,“右键>run astjunit

24、test”运彳亍成功,说明hibernate配置搭建成功spring的集成a)、为工程添加spring,右击工程文件,在弹出的右键菜单中选中myeclipse节点下的add spring capabilities,这时即将弹出如卜窗口add spring capabilities在这里我们勾选所需项,如卜图所示spring 1 2spring 1 2spring 1 2spring 1.2aop librari es 一 <myeclipse"library>core libraries - <myeclipse"library>orm/dao/hi

25、bernate3 libraries - yeclipse"library>orm/dao/hibernate2 libraries - <jflyeclipse"library>spring 1.2 testing support libraries - oflyeclipsespring 1.2 web libraries - <jflyeclipselibrary>jar library install注tionodd checked libraries to project buildupath八g隔.c)、单击next,如卜图&quo

26、t;add spring capabilitiesadd spring capabilitiesadd spring bean configuretion file0specify new or existing spring bean configuration file?bean configuration type: ©newc*existingfolder: srcbrowsefile:applicationcontext. xml<back>fini shcanceld)、继续单rlf next如下图f).在这里,我们选取keep existing以完成spri

27、ng的集成,e)x在这里设置好sessionfactory id为mysessionfactory,其中id属性值可随意命名此时单击 finish,你将会看到如下界而:到这里我们以完成了 spring的集成,最后我们要通过spring来代理struts的action类g).百先,我们在hibda0新添加一个方法252627-28-29303132-333435-3637-38public voidsystem, out. print in (oh, yeah 个方法是通过spiring注入的,恭喜你,你的spring己经成功了”);h)为使spring和struts能集成,需要在struts-

28、config.xml文件中添加如下代码:<!_控制反辄动态代section实则><controller><set-property property2wprocessorclassr, value=,forg.springfraineijoi:上®eb.strutsdelegatingrequestprocessorrf /> </controller><ffiessage-resourcesparameter=wcom.jb.arui.ueb.struts.app1icatlonresourcesw /><!配置sp

29、ringffi件卅手struts + spring的愁t集成><pluginclassname=ftorg.springfrainetork. web struts. concextloaderplugin,r><set-property property=rfcontextconfiglocation,f value=rt/web-inf/applicationcontext.x»irf /> </plug-in>其中vmessage-resources />应该早就冇的,z所以这样写,是因为顺序问题, <controller></controller>ji&l<message-resources /> 之前而 <plugi-in></plug-in>hyiie<message-resources /> 之肩最后在 struts-config.xml 文件里的 vaction-mappings ></ action-mappings节点下的vaction /> 里头可以无需在写type属性了,因为将会通过spring来代理.i) >现在,我们在com.jb.arui.web.strut

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论