xml文件: <?xml version="1.0" encoding="UTF-8"?> <url-filter> <str-config> <str-value>index</str-value> <str-inneed>0</str-inneed> </str-config> <str-config> <str-value>MyJsp</str-value> <str-inneed>1</str-inneed> </str-config> </url-filter> java文件: package com; import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class urlConfDao { String URL_FILTER_CONFIG="/AppLog/Config/WapPush/urlFilter_config.xml"; String INDEX_URL="/index.jsp"; /** * 读取配置文件,返回配置的List * @return */ public List getUrlConfigList() { List list = new ArrayList(); try { File f = this.getConfFile(); SAXReader reader = new SAXReader(); Document doc = reader.read(f); Element root = doc.getRootElement(); Element foo; for (Iterator i = root.elementIterator("str-config"); i.hasNext();) { foo = (Element) i.next(); urlConfBean uc = new urlConfBean(); uc.setStr_value(foo.elementText("str-value")); String str_inneed_tmp = foo.elementText("str-inneed"); if(str_inneed_tmp==null||str_inneed_tmp.equals("")) str_inneed_tmp="-1"; uc.setStr_inneed(Integer.parseInt(str_inneed_tmp)); list.add(uc); System.out.print("字符串:" + uc.getStr_value()); System.out.println(" 是否需要:" + uc.getStr_inneed()); } } catch (Exception e) { e.printStackTrace(); } return list; } public File getConfFile() { File file = new File(URL_FILTER_CONFIG); return file; } }