基于Struts+Spring+JDBC架構(gòu)的課程設(shè)計(jì)實(shí)訓(xùn)教學(xué)示例項(xiàng)目——《網(wǎng)上銀行賬戶管理系統(tǒng)》——在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能_第1頁(yè)
基于Struts+Spring+JDBC架構(gòu)的課程設(shè)計(jì)實(shí)訓(xùn)教學(xué)示例項(xiàng)目——《網(wǎng)上銀行賬戶管理系統(tǒng)》——在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能_第2頁(yè)
基于Struts+Spring+JDBC架構(gòu)的課程設(shè)計(jì)實(shí)訓(xùn)教學(xué)示例項(xiàng)目——《網(wǎng)上銀行賬戶管理系統(tǒng)》——在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能_第3頁(yè)
基于Struts+Spring+JDBC架構(gòu)的課程設(shè)計(jì)實(shí)訓(xùn)教學(xué)示例項(xiàng)目——《網(wǎng)上銀行賬戶管理系統(tǒng)》——在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能_第4頁(yè)
基于Struts+Spring+JDBC架構(gòu)的課程設(shè)計(jì)實(shí)訓(xùn)教學(xué)示例項(xiàng)目——《網(wǎng)上銀行賬戶管理系統(tǒng)》——在項(xiàng)目中實(shí)現(xiàn)對(duì)XML文件進(jìn)行解析的各種功能_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(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)上銀行賬戶管理系統(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)類(1)接口名稱為XMLInformationConfig,包名稱為(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)類(1)添加SAXInformationConfig類類名稱為SAXInformationConfig,包名稱為,基類為tHandler(采用SAX技術(shù))。(2)編程該SAXInformationConfig類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工廠對(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類中的xmlInit方法中出現(xiàn)ParserConfigurationException);catch (SAXException se)throw new WebBankException(在SAXInformationConfig類中的xmlInit方法中出現(xiàn)SAXException);catch (java.io.IOException ioe)throw new WebBankException(在SAXInformationConfig類中的xmlInit方法中出現(xiàn)IOException);catch (Exception ex)t

7、hrow new WebBankException(在SAXInformationConfig類中的xmlInit方法中出現(xiàn)Exception);finallysaxParserFactory = null;saxParser = null;private String tagElementName = null;/定義開(kāi)始解析元素的方法. 這里是將中的名稱xxx提取出來(lái).public void startElement(String uri, String localName, String qName, Attributes attributes)throws SAXExceptionth

8、is.tagElementName = qName; /獲得該標(biāo)簽的名稱/這里是將之間的標(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)類提供一個(gè)工廠類XMLInformationConfigFactory(1)用來(lái)統(tǒng)一創(chuàng)建XMLInformationConfig接口的對(duì)象實(shí)例名稱為XMLInformationConfigFactory類,包名稱為 ,并且從類繼承。(2)編程該XMLInformationConfigFactory類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è)觀察者throw new WebBankException(不能正確地獲得+xmlInformationConfigImpleClassName+類);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è)觀察者throw new WebBankException(不能正確地創(chuàng)建+xmlInformationConfigImpleClassName+類的對(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è)觀察者throw new WebBankException(不能正確地創(chuàng)建+xmlInformationConfigImpleClassName+類的對(duì)象實(shí)例);return oneXMLInformationConfigImple;4、修改classNameConfig.xml文件以添加對(duì)SAXInformation

15、Config類的定義sName5、在WebBankListener類中對(duì)上面的SAXInformationConfig類進(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)在線人員數(shù)比較多時(shí),開(kāi)銷比較大!private ServletContext oneServletContext=null;public void sessionCreated( SessionEvent arg0) /某用戶訪問(wèn),將增加訪問(wèn)計(jì)數(shù)總數(shù)OnLineCounter.addOneUser();public void sessionDestroy

19、ed( SessionEvent arg0) OnLineCounter.reduceOneUser();/某用戶離線,將減少訪問(wèn)計(jì)數(shù)總數(shù)public void attributeAdded( SessionBindingEvent SessionBindingEvent)/識(shí)別該用戶是否已經(jīng)登錄if( SessionBindingEvent.getName().equals(oneUserInfoVO)UserInfoVO nowLoginUserInfo=(UserInfoVO) SessionBindingEvent.getValue();onLineUserList.add(nowLo

20、ginUserInfo);/* * 一旦該用戶登陸成功,將減少“游客”的計(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);/除掉該登陸用戶的信息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類中的contextInitialized方法出現(xiàn)了We

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論