欢迎来到天天文库
浏览记录
ID:40641597
大小:23.60 KB
页数:15页
时间:2019-08-05
《学生管理系统 java xml》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//账号密码设置类//注意还需要dom4j-1.6.1的jar包和新建两个xml文件packagecn.primaryItem;publicclassLanding{privateStringlandName;privateStringlandPass;publicLanding(){}publicLanding(StringlandName,StringlandPass){this.landName=landName;this.landPass=landPass;}publicStringgetLandName(){returnlandName
2、;}publicvoidsetLandName(StringlandName){this.landName=landName;}publicStringgetLandPass(){returnlandPass;}publicvoidsetLandPass(StringlandPass){this.landPass=landPass;}}//账号密码功能的实现packagecn.primaryItem;importjava.io.File;importjava.io.FileOutputStream;importjava.io.OutputStre
3、am;importjava.util.Iterator;importjava.util.List;importorg.dom4j.Document;importorg.dom4j.DocumentException;importorg.dom4j.Element;importorg.dom4j.io.OutputFormat;importorg.dom4j.io.SAXReader;importorg.dom4j.io.XMLWriter;publicclassLandingUtil{//忘记密码publicLandingForget(Strin
4、glandName){Landinglanding=null;Documentdocument=getDocument();//获取根元素Elementelement=document.getRootElement();//获取子元素@SuppressWarnings("unchecked")Listlist=element.elements();Iteratorit=list.iterator();while(it.hasNext()){Elementel=it.next();Stringname=el.el
5、ement("landName").getText();if(name.equals(landName)){landing=newLanding();landing.setLandPass(el.elementText("landPass"));}}returnlanding;}//读取密码publicbooleanread(Landinglanding){booleanbn=false;Documentdocument=getDocument();//获取根元素Elementelement=document.getRootElement();/
6、/获取子元素@SuppressWarnings("unchecked")Listlist=element.elements();Iteratorit=list.iterator();while(it.hasNext()){Elementel=it.next();Stringname=el.element("landName").getText();Stringpass=el.element("landPass").getText();if(name.equals(landing.getLandName())&&
7、pass.equals(landing.getLandPass())){bn=true;}}returnbn;}//添加账号和密码publicbooleanadd(Landinglanding){booleanbn=false;Stringregex="^[A-Za-z0-9]";//获取document对象Documentdocument=getDocument();//获取根元素Elementroot=document.getRootElement();//添加子元素Elementelement=root.addElement("landin
8、g");element.addElement("landName").setText(landing.getLandName());El
此文档下载收益归作者所有