




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、基于Struts+Spring+JDBC架構(gòu)的課程設(shè)計(jì)實(shí)訓(xùn)教學(xué)示例項(xiàng)目網(wǎng)上銀行賬戶(hù)管理系統(tǒng)在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能1、添加一個(gè)對(duì)XML進(jìn)行解析的JavaBean組件的接口及實(shí)現(xiàn)類(lèi)(1)接口名稱(chēng)為XMLInformationConfig,包名稱(chēng)為(2)設(shè)計(jì)該接口package com.px1987.webbank.util;import com.px1987.webbank.exception.*;public interface XMLInformationConfig public void xmlInit(String confi
2、gFilePathAndName) throws WebBankException;2、為上面的接口提供一個(gè)實(shí)現(xiàn)類(lèi)(1)添加SAXInformationConfig類(lèi)類(lèi)名稱(chēng)為SAXInformationConfig,包名稱(chēng)為,基類(lèi)為tHandler(采用SAX技術(shù))。(2)編程該SAXInformationConfig類(lèi)package com.px1987.webbank.util;import org.xml.sax.helpers.DefaultHandler;import com.px1987.webbank.exception.WebBankException;import java.
3、io.*;import org.xml.sax.Attributes;ion;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;public class SAXInformationConfig extends DefaultHandler implements XMLInformationConfigprivate String marqueeText = ;public String getMarqueeText()return marqueeText;public SAXInforma
4、tionConfig()/* * 讀取配置文件信息,并設(shè)置相關(guān)參數(shù)。 * param configFileName String 配置文件路徑及文件名。 */public void xmlInit(String configFilePathAndName) throws WebBankExceptionSAXParserFactory saxParserFactory = null;SAXParser saxParser = null;saxParserFactory = SAXParserFactory.newInstance(); /獲取SAX工廠(chǎng)對(duì)象saxParserFactory.se
5、tNamespaceAware(false);saxParserFactory.setValidating(false);trysaxParser = saxParserFactory.newSAXParser(); /創(chuàng)建出SAX解析/*將解析器和解析對(duì)象XMLDOMData.xml聯(lián)系起來(lái),同時(shí)指定事件回調(diào)方法的對(duì)象開(kāi)始解析*/saxParser.parse(new File(configFilePathAndName), this);catch (javax.xml.parsers.ParserConfigurationException pe)throw new WebBankExce
6、ption(在SAXInformationConfig類(lèi)中的xmlInit方法中出現(xiàn)ParserConfigurationException);catch (SAXException se)throw new WebBankException(在SAXInformationConfig類(lèi)中的xmlInit方法中出現(xiàn)SAXException);catch (java.io.IOException ioe)throw new WebBankException(在SAXInformationConfig類(lèi)中的xmlInit方法中出現(xiàn)IOException);catch (Exception ex)t
7、hrow new WebBankException(在SAXInformationConfig類(lèi)中的xmlInit方法中出現(xiàn)Exception);finallysaxParserFactory = null;saxParser = null;private String tagElementName = null;/定義開(kāi)始解析元素的方法. 這里是將中的名稱(chēng)xxx提取出來(lái).public void startElement(String uri, String localName, String qName, Attributes attributes)throws SAXExceptionth
8、is.tagElementName = qName; /獲得該標(biāo)簽的名稱(chēng)/這里是將之間的標(biāo)簽體的值加入到currentValuepublic void characters(char ch, int start, int length) throws SAXExceptionString tagBodyText = new String(ch, start, length); /獲得標(biāo)簽體的文字串內(nèi)容if (this.tagElementName.equals(marquee-text) & !tagBodyText.trim().equals()marqueeText = tagBodyTe
9、xt;3、為SAXInformationConfig實(shí)現(xiàn)類(lèi)提供一個(gè)工廠(chǎng)類(lèi)XMLInformationConfigFactory(1)用來(lái)統(tǒng)一創(chuàng)建XMLInformationConfig接口的對(duì)象實(shí)例名稱(chēng)為XMLInformationConfigFactory類(lèi),包名稱(chēng)為 ,并且從類(lèi)繼承。(2)編程該XMLInformationConfigFactory類(lèi)package com.px1987.webbank.factory;import java.util.Observable;import com.px1987.webbank.config.ClassNameConfig;ebbank.exc
10、eption.WebBankException;import com.px1987.webbank.util.*;public class XMLInformationConfigFactory extends Observable public XMLInformationConfigFactory() public XMLInformationConfig newXMLInformationConfigBean(String xmlInformationConfigImpleClassName) throws WebBankExceptionXMLInformationConfig one
11、XMLInformationConfigImple=null;Class oneClass=null;try oneClass = Class.forName(xmlInformationConfigImpleClassName); catch (ClassNotFoundException e)int logImpleKind=Integer.parseInt(ClassNameConfig.getProperty(logImpleKind);this.addObserver(LogInfoFactory.newLogInstance(logImpleKind);this.setChange
12、d(); /注意要設(shè)置變化點(diǎn)notifyObservers(e);/當(dāng)出現(xiàn)異常時(shí)將通知各個(gè)觀(guān)察者throw new WebBankException(不能正確地獲得+xmlInformationConfigImpleClassName+類(lèi));try oneXMLInformationConfigImple = (XMLInformationConfig)oneClass.newInstance(); catch (InstantiationException e)int logImpleKind=Integer.parseInt(ClassNameConfig.getProperty(logI
13、mpleKind);this.addObserver(LogInfoFactory.newLogInstance(logImpleKind);this.setChanged(); /注意要設(shè)置變化點(diǎn)notifyObservers(e);/當(dāng)出現(xiàn)異常時(shí)將通知各個(gè)觀(guān)察者throw new WebBankException(不能正確地創(chuàng)建+xmlInformationConfigImpleClassName+類(lèi)的對(duì)象實(shí)例); catch (IllegalAccessException e)int logImpleKind=Integer.parseInt(ClassNameConfig.getPro
14、perty(logImpleKind);this.addObserver(LogInfoFactory.newLogInstance(logImpleKind);this.setChanged(); /注意要設(shè)置變化點(diǎn)notifyObservers(e);/當(dāng)出現(xiàn)異常時(shí)將通知各個(gè)觀(guān)察者throw new WebBankException(不能正確地創(chuàng)建+xmlInformationConfigImpleClassName+類(lèi)的對(duì)象實(shí)例);return oneXMLInformationConfigImple;4、修改classNameConfig.xml文件以添加對(duì)SAXInformation
15、Config類(lèi)的定義sName5、在WebBankListener類(lèi)中對(duì)上面的SAXInformationConfig類(lèi)進(jìn)行使用package com.px1987.webbank.listener;import java.util.ArrayList;import java.util.List;import java.util.Timer;import javax.servlet.ServletContext;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import
16、javax.servlet. . SessionAttributeListener;import javax.servlet. . SessionBindingEvent;import javax.servlet. . SessionEvent;import javax.servlet. . SessionListener;import com.px1987.webbank.config.ClassNameConfig;import com.px1987.webbank.exception.WebBankException;import com.px1987.webbank.factory.X
17、MLInformationConfigFactory;import com.px1987.webbank.model.vo.UserInfoVO;import com.px1987.webbank.util.OnLineCounter;import com.px1987.webbank.util.WebBankScheduleTask;import com.px1987.webbank.util.XMLInformationConfig;public class WebBankListener implements SessionListener, SessionAttributeListen
18、er, ServletContextListener private String saxXMLPathAndFileName=null;private static List onLineUserList=new ArrayList();/當(dāng)在線(xiàn)人員數(shù)比較多時(shí),開(kāi)銷(xiāo)比較大!private ServletContext oneServletContext=null;public void sessionCreated( SessionEvent arg0) /某用戶(hù)訪(fǎng)問(wèn),將增加訪(fǎng)問(wèn)計(jì)數(shù)總數(shù)OnLineCounter.addOneUser();public void sessionDestroy
19、ed( SessionEvent arg0) OnLineCounter.reduceOneUser();/某用戶(hù)離線(xiàn),將減少訪(fǎng)問(wèn)計(jì)數(shù)總數(shù)public void attributeAdded( SessionBindingEvent SessionBindingEvent)/識(shí)別該用戶(hù)是否已經(jīng)登錄if( SessionBindingEvent.getName().equals(oneUserInfoVO)UserInfoVO nowLoginUserInfo=(UserInfoVO) SessionBindingEvent.getValue();onLineUserList.add(nowLo
20、ginUserInfo);/* * 一旦該用戶(hù)登陸成功,將減少“游客”的計(jì)數(shù) */ Integer onLineGuest=(Integer)oneServletContext.getAttribute(onLineGuest);int onLineGuestDigit=onLineGValue();oneServletContext.setAttribute(onLineGuest,new Integer(onLineGuestDigit-1)=0?(onLineGuestDigit-1):0);public void attributeRemoved( SessionBindingEven
21、t SessionBindingEvent)if( SessionBindingEvent.getName().equals(oneUserInfoVO)UserInfoVO nowLoginUserInfo=(UserInfoVO) SessionBindingEvent.getValue();onLineUserList.remove(nowLoginUserInfo);/除掉該登陸用戶(hù)的信息public void attributeReplaced( SessionBindingEvent SessionBindingEvent)public static List getOnLineU
22、serList()return onLineUserList;public void contextDestroyed(ServletContextEvent arg0) scheduletimer.cancel();private Timer scheduletimer = null;public void contextInitialized(ServletContextEvent arg0) oneServletContext=arg0.getServletContext(); XMLInformationConfig xmlSaxInfoBeanID=null;saxXMLPathAn
23、dFileName=oneServletContext.getInitParameter(saxXMLPathAndFileName); String saxXMLFileName=oneServletContext.getRealPath()+saxXMLPathAndFileName; try String xmlInformationConfigImpleClassName=ClassNameConfig.getProperty(xmlInformationConfigImple.className); xmlSaxInfoBeanID=new XMLInformationConfigFactory().newXMLInformationConfigBean(xmlInformationConfigImpleClassName); catch(WebBankException e) e.printStackTrace(); try xmlSaxInfoBeanID.xmlInit(saxXMLFileName); catch (WebBankException e) e.printStackTrace(); System.out.println(在WebBankListener類(lèi)中的contextInitialized方法出現(xiàn)了We
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 潛水裝備的水下作業(yè)安全意識(shí)培養(yǎng)與提升考核試卷
- 舞蹈教育在兒童成長(zhǎng)中的作用考核試卷
- 窗簾面料的環(huán)保染整技術(shù)考核試卷
- 四川水利職業(yè)技術(shù)學(xué)院《臨床檢驗(yàn)儀器與技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西省運(yùn)城市萬(wàn)榮縣2025年初三下學(xué)期第二次模擬考試化學(xué)試題文試卷含解析
- 山東省威海市文登區(qū)文登實(shí)驗(yàn)、三里河中學(xué)2025屆中考化學(xué)試題模擬試卷(8)含解析
- 沈陽(yáng)工業(yè)大學(xué)《現(xiàn)代地球物理學(xué)進(jìn)展》2023-2024學(xué)年第二學(xué)期期末試卷
- 濰坊學(xué)院《大學(xué)寫(xiě)作實(shí)踐課》2023-2024學(xué)年第二學(xué)期期末試卷
- 景德鎮(zhèn)市重點(diǎn)中學(xué)2024-2025學(xué)年初三考前熱身生物試題試卷含解析
- 天門(mén)職業(yè)學(xué)院《應(yīng)用真菌學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 醬酒行業(yè)發(fā)展趨勢(shì)分析
- 《紅樓夢(mèng)》賈府平面圖
- 養(yǎng)老機(jī)構(gòu)全套服務(wù)管理流程圖()
- 運(yùn)用PDCA辦法提高分級(jí)護(hù)理落實(shí)率
- 高級(jí)卒中中心申報(bào)操作流程
- 幼兒園幼兒小籃球活動(dòng)體能測(cè)試表
- 遠(yuǎn)盛水工重力壩輔助設(shè)計(jì)系統(tǒng)用戶(hù)使用手冊(cè)
- 通用城實(shí)景三維數(shù)據(jù)生產(chǎn)項(xiàng)目技術(shù)設(shè)計(jì)書(shū)
- 畢業(yè)設(shè)計(jì)(論文)-N402—1300型農(nóng)用拖拉機(jī)履帶底盤(pán)的設(shè)計(jì)
- 巖棉項(xiàng)目申報(bào)書(shū)_參考模板
- 施工組織設(shè)計(jì)方案交底記錄
評(píng)論
0/150
提交評(píng)論