




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、struts1.2+spring2.5+hibernate3.2框架搭建(一)1. 準(zhǔn)備. 21.1.創(chuàng)建工程. 21.2.在工程中建包. 32. struts 部分. 32.1. 添加 struts 功能支持. 32. 2.創(chuàng)建 actionform 類 . 52.3. 創(chuàng)建 action 類. 62.4. 創(chuàng)建jsp 文件. 82.5.修改action類. 102.6.測(cè)試struts框架. 123.spring 部分. 123.1. 添加 spring 功能支持. 123.2. 配置 web.xml 文件. 153.3. 配置 struts-config.xml 文件. 193.4. 修
2、改 spring 配置文件 applicationcontext.xml 193.5. 增加log4j日志功能. 193.6. 測(cè)試 . 214. hibernate 部分. 214.1. 創(chuàng)建 sqlserver2000 數(shù)據(jù)庫(kù)和表. 214.2. 創(chuàng)建 myeclipse 數(shù)據(jù)庫(kù)驅(qū)動(dòng)(db driver). 224.3. 添加 hibernate 功能支持. 244.4. 創(chuàng)建對(duì)象關(guān)系映射(orm)的相關(guān)文件. 314.5. 創(chuàng)建數(shù)據(jù)層: iusersdao.java 接口和 usersdaoimpl.java 類,業(yè)務(wù)層:iusersbusiness.java接口和usersbusine
3、ssimpl.java類。. 354.6. 修改 loginaction.java 文件. 394.7. 修改spring配制文件 applicationcontext.xml 424.8. 測(cè)試. 45struts1.2+spring2.5+hibernate3.2框架搭建1. 準(zhǔn)備 工具:myeclipse 8.0 ga、tomcat 6.0環(huán)境:struts1.2、spring2.5、hibernate3.2、sqlserver20001.1.創(chuàng)建工程 1.2.在工程中建包 com.zlk.business業(yè)務(wù)層接口類com.zlk.business.impl業(yè)務(wù)層實(shí)現(xiàn)類com.zlk.
4、dao數(shù)據(jù)層接口類com.zlk.dao.impl數(shù)據(jù)層實(shí)現(xiàn)類com.struts.action控制層com.struts.form2. struts 部分 2.1. 添加 struts 功能支持 操作:右擊項(xiàng)目 myeclipse /add struts capabilities操作:修改struts類所在的包2.2.創(chuàng)建 actionform 類操作:打開(kāi)struts的設(shè)計(jì)頁(yè)面,右擊 new/form,action,and jsp類名:loginform在 form properties 選項(xiàng)卡為 loginform 新增兩個(gè)屬性:username、password;2.3. 創(chuàng)建 act
5、ion 類類名:loginaction在“parameter選項(xiàng)卡”中把parameter的值設(shè)置成“methods”2.4. 創(chuàng)建jsp 文件index.jsp代碼 login.jsp代碼 base href= my jsp login.jsp starting page !- - ssh框架搭建測(cè)試登陸. form action=/login.do?methods=login method=post input type=button value=注冊(cè) onclick=window.location.href=/register.jsp struts1.2+spring2.5+hibern
6、ate3.2框架搭建(二)register.jsp代碼 base href= my jsp register.jsp starting page !- - ssh框架搭建測(cè)試注冊(cè). form action=/login.do?methods=register method=post input type=button value=返回 onclick=window.location.href=/login.jsp 2.5.修改action類 操作:添加login和register兩個(gè)方法,其中register類先空著等添加完hibernate之后在改寫(xiě),login方法先為檢測(cè)struts是否添
7、加成功只在服務(wù)端檢測(cè)用戶為:zhoulukang 密碼為:123的用戶登陸。/* generated by myeclipse struts* template path: templates/java/javaclass.vtl*/package com.zlk.struts.action;import java.io.ioexception;import java.io.printwriter;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import o
8、rg.apache.struts.action.actionform;import org.apache.struts.action.actionforward;import org.apache.struts.action.actionmapping;import org.apache.struts.actions.dispatchaction;import com.zlk.struts.form.loginform;/* * myeclipse struts* creation date: 03-05-2010* * xdoclet definition:* struts.action p
9、ath=/login name=loginform parameter=methods scope=request validate=true*/public class loginaction extends dispatchaction /* * generated methods */ /* * 登陸的方法 */ public actionforward login(actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) loginform logi
10、nform = (loginform) form;/ todo auto-generated method stub response.setcontenttype(text/html;charset=utf-8); printwriter out = null; try out = response.getwriter(); if(loginform.getusername().equals(zhoulukang)&loginform.getpassword().equals(123) out.print(+loginform.getusername()+恭喜你登陸成功!); else ou
11、t.println(對(duì)不起,登陸失敗); catch (ioexception e) / todo auto-generated catch block e.printstacktrace(); return null; /* * 注冊(cè)的方法 */ public actionforward register(actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) loginform loginform = (loginform) form;/ todo a
12、uto-generated method stub return null; 2.6.測(cè)試struts框架 操作:輸入用戶名密碼操作:點(diǎn)擊登陸struts1.2+spring2.5+hibernate3.2框架搭建(三) 3.spring 部分 3.1. 添加 spring 功能支持 操作:右擊項(xiàng)目 myeclipse/add spring capabilities開(kāi)發(fā)包選擇:spring2.5 aop libraries、spring 2.5 core libraries、spring 2.5 persistence core libraries、spring 2.5 persistence
13、 jdbc libraries、 spring2.5 web librariesjar library installation 選擇 copy checked. ,tag library folder 項(xiàng)選擇 /webroot/web-inf/lib(這樣的話所需的類庫(kù)都將拷貝到項(xiàng)目目錄,方便以后的布署)。點(diǎn)擊 下一步(next) 創(chuàng)建配置文件,修改文件路徑(folder)到 src 目錄,文件名稱為默認(rèn)的applicationcontext.xml。選擇完成。struts1.2+spring2.5+hibernate3.2框架搭建(四) 3.2. 配置 web.xml 文件 在web.xm
14、l文件中配置監(jiān)聽(tīng)器以及web應(yīng)用的初始化參數(shù): contextconfiglocation classpath:applicationcontext.xml org.springframework.web.context.contextloaderlistener characterencodingfilter org.springframework.web.filter.characterencodingfilter encoding utf-8 forceencoding true characterencodingfilter /*在web.xml文件中配置spring中的過(guò)濾器解決hi
15、bernate延遲加載的問(wèn)題 opensessioninviewfilter com.zlk.util.opensessioninviewfilter singlesession true opensessioninviewfilter /*注:我重寫(xiě)了org.springframework.orm.hibernate3.support.opensessioninviewfilter類下面是我重寫(xiě)的類: com.zlk.override.opensessioninviewfilterpackage com.zlk.override;import org.hibernate.flushmode;
16、import org.hibernate.session;import org.hibernate.sessionfactory;import org.springframework.dao.dataaccessresourcefailureexception;import org.springframework.orm.hibernate3.sessionfactoryutils;public class opensessioninviewfilter extends org.springframework.orm.hibernate3.support.opensessioninviewfi
17、lter protected void closesession(session session, sessionfactory sessionfactory) / todo auto-generated method stub session.flush(); super.closesession(session, sessionfactory); protected session getsession(sessionfactory sessionfactory) throws dataaccessresourcefailureexception / todo auto-generated
18、 method stub session session = sessionfactoryutils.getsession(sessionfactory, true); this.setflushmode(flushmode.commit); return session; com.zlk.util.opensessioninviewfilterpackage com.zlk.util;public class opensessioninviewfilter extends com.zlk.override.opensessioninviewfilter struts1.2+spring2.5
19、+hibernate3.2框架搭建(五)配置好以后的web.xml文件為: contextconfiglocation classpath:applicationcontext.xml org.springframework.web.context.contextloaderlistener action org.apache.struts.action.actionservlet config /web-inf/struts-config.xml debug 3 detail 3 0 action *.do characterencodingfilter org.springframewor
20、k.web.filter.characterencodingfilter encoding utf-8 forceencoding true opensessioninviewfilter com.zlk.util.opensessioninviewfilter singlesession true characterencodingfilter /* opensessioninviewfilter /* index.jsp 3.3. 配置 struts-config.xml 文件 在和標(biāo)簽之間添加如下代碼,實(shí)現(xiàn)讓spring代理action 3.4. 修改 spring 配置文件 appli
21、cationcontext.xml 粗體字是關(guān)于接受和處理 action 控制權(quán)的配置內(nèi)容,com.login.struts.action.loginaction 即為原 struts 里的配置。struts1.2+spring2.5+hibernate3.2框架搭建(六)3.5. 增加log4j日志功能 增加日志功能方便調(diào)試程序,perties文件如下(放到工程src根目錄下)# this is the configuring for logging displayed in the application serverlog4j.rootcategory=info, st
22、dout# replace the line above if you want to put a log file into the directory # you start tomcat from# log4j.rootcategory=info, stdout, rlog4j.appender.stdout=org.apache.log4j.consoleappenderlog4j.appender.stdout.layout=org.apache.log4j.patternlayout# pattern to output the callers file name and line
23、 number.log4j.appender.stdout.layout.conversionpattern=u5de5u7a0bu53c2u6570uff1a %p %t %c1.%m(%l) | %m%nlog4j.appender.r=org.apache.log4j.rollingfileappender# you can change this to be an absolute path or even an environment variable# if youre using an environment variable, you will have to set java
24、_opts# to contain this variables - for example in the catalina.sh or catalina# filelog4j.appender.r.file=appname.loglog4j.appender.r.maxfilesize=100kb# dont keep a backup filelog4j.appender.r.maxbackupindex=0log4j.appender.r.layout=org.apache.log4j.patternlayoutlog4j.appender.r.layout.conversionpatt
25、ern=%p %t %c - %m%n# configuration for receiving e-mails when error messages occur.log4j.appender.mail=.smtpappenderlog4j.appender.mail.to=error-mailtolog4j.appender.mail.from=error-serverlog4j.appender.mail.smtphost=error-mailhostlog4j.appender.mail.threshold=er
26、rorlog4j.appender.mail.buffersize=1log4j.appender.mail.subject=error-server appname application errorlog4j.appender.mail.layout=org.apache.log4j.patternlayoutlog4j.appender.mail.layout.conversionpattern=%d %-5p %c %x - %m%n# if programmed properly the most messages would be at debug # and the least
27、at fatal..appfuse=debug.appfuse.webapp.filter=error.appfuse.webapp.listener.usercounterlistener=warn.appfuse.util=warn# control logging for other open source .opensymphony.oscache=error.sf.navigat
28、or=errormons=error.apache.struts=warn.displaytag=error.springframework=warn.ibatis.db=warn.apache.velocity=fatal# dont show debug logs for webt.canoo.webtest=warn# all hibern
29、ate log output of info level or higher goes to stdout.# for more verbose logging, change the info to debug on the last .sf.hibernate.ps.preparedstatementcache=warn.sf.hibernate=warn.hebnews.seven.util.autorun=all注意: add struts capabilities時(shí)并沒(méi)有加
30、入log4j.jar包,為了提供log4j功能,需要加上log4j.jar。這里是因?yàn)閷?dǎo)入spring的時(shí)候附帶導(dǎo)入了log4j.jar包,所以此處不用再另外導(dǎo)入log4j.jar包3.6. 測(cè)試同上一次測(cè)試。測(cè)試成功證明 spring 運(yùn)行正常。struts1.2+spring2.5+hibernate3.2框架搭建(七)4. hibernate 部分 下面開(kāi)始 hibernate 部分,將原例修改為使用數(shù)據(jù)庫(kù)進(jìn)行用戶名/密碼驗(yàn)證和注冊(cè)。4.1. 創(chuàng)建 sqlserver2000 數(shù)據(jù)庫(kù)和表 添加表其中有id(標(biāo)識(shí)),username,和password字段:sql代碼如下:if exist
31、s (select * from dbo.sysobjects where id = object_id(ndbo.users) and objectproperty(id, nisusertable) = 1)drop table dbo.usersgocreate table dbo.users ( id int identity (1, 1) not null , username varchar (50) collate chinese_prc_ci_as null , password varchar (50) collate chinese_prc_ci_as null ) on
32、primarygo4.2. 創(chuàng)建 myeclipse 數(shù)據(jù)庫(kù)驅(qū)動(dòng)(db driver)在 db brower 的右鍵菜單中選擇 new“driver template”項(xiàng)選擇microsoft sql server,driver name 項(xiàng)輸入 sql2000 ,connection url 為jdbc:microsoft:sqlserver:/localhost:1433;databasename=test ,然后輸入正確的用戶名(user name)和密碼(password)按實(shí)際情況輸入,點(diǎn)擊”add jars”按鈕添加sqlserver2000jdbc直連包:msbase.jar、mssqlserver.jar、msutil.jar,選中”save password”選項(xiàng)。點(diǎn)擊”下一步(next)”點(diǎn)擊 完成(finish)。接下去即可以
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2021-2026年中國(guó)中頻熔煉電爐市場(chǎng)深度分析及投資戰(zhàn)略咨詢報(bào)告
- 2025年 昌吉州招聘中學(xué)教師筆試試題附答案
- 2025年中國(guó)云終端行業(yè)市場(chǎng)調(diào)查研究及投資前景預(yù)測(cè)報(bào)告
- 2025年電影放映項(xiàng)目深度研究分析報(bào)告
- 高性能絕緣材料項(xiàng)目可行性研究報(bào)告方案可用于立項(xiàng)及銀行貸款+201
- 1000噸年鋁基復(fù)合材料建設(shè)投資項(xiàng)目可行性實(shí)施報(bào)告
- 紗布底植絨布項(xiàng)目投資可行性研究分析報(bào)告(2024-2030版)
- 社區(qū)危舊房改造項(xiàng)目可行性研究報(bào)告
- 2025年中國(guó)分動(dòng)器行業(yè)發(fā)展運(yùn)行現(xiàn)狀及投資潛力預(yù)測(cè)報(bào)告
- 中國(guó)防縮無(wú)結(jié)針織紗行業(yè)市場(chǎng)發(fā)展前景及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告(2024-2030)
- DB32∕T 186-2015 建筑消防設(shè)施檢測(cè)技術(shù)規(guī)程
- 巡檢培訓(xùn)課件.ppt
- 北師大版五下書(shū)法《第6課戈字旁》課件
- 二代征信系統(tǒng)數(shù)據(jù)采集規(guī)范釋義
- 軸承基礎(chǔ)知識(shí)PPT通用課件
- 蘇教版二年級(jí)(下冊(cè))科學(xué)全冊(cè)單元測(cè)試卷含期中期末(有答案)
- 國(guó)家開(kāi)放大學(xué)電大本科《設(shè)施園藝學(xué)》2023-2024期末試題及答案(試卷代號(hào):1329)
- 數(shù)列求和(錯(cuò)位相減法)
- 固廢中心廢氣處理方案
- 關(guān)于地理高考四大能力要求解讀
- 滅火救援作戰(zhàn)計(jì)劃圖例
評(píng)論
0/150
提交評(píng)論