<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<add key="AD-DOMAIN" value="jspdi"></add>
<add key="AD-IP" value="172.17.16.1"></add>
<add key="com-domain" value="内网=http://172.17.17.105:8090;外网=http://218.94.40.4:8090"></add>
</configuration>
package com.pm360.pip.util.util;
import java.io.File;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ReadConfig
{
@SuppressWarnings("unchecked")
public static String readConfig(HttpServletRequest request,String configName)
{
String configValue="";
SAXReader reader=new SAXReader();
Document dt;
try {
String uri=request.getRealPath("\\")+"WEB-INF\\projinfo-config.xml";
dt = reader.read(new File(uri));
List<Element>list=dt.selectNodes("/configuration/add");
for (Element element : list)
{
String key=element.attribute("key").getValue();
String value=element.attribute("value").getValue();
if(key.equals(configName))
configValue=value;
}
} catch (DocumentException e) {
e.printStackTrace();
}
return configValue;
}
}