<Context path= "/eLink "
reloadable= "true "
docBase= "E:\Project\eLink "
workDir= "E:\Project\eLink\work "
SQLFile = "E:\Project\SQLFILE.xml "
/>
例如这样一个项目,我向读取 SQLFile参数,应该如何写代码?
------解决方案--------------------
关注中.
------解决方案--------------------
你要读取什么参数? 为什么不写在Parameter元素中呢
------解决方案--------------------
在哪个文件 的?Web.xml?
-----------------------
http://blog.xerik.cn (专注于Java技术)
------解决方案--------------------
使用JDOM
import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.xpath.*;
public class jdomTool {
public static void main(String[] args) throws IOException, JDOMException {
String filename = "D://Web.xml ";
PrintStream out = System.out;
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File(filename));
// Print param information
XPath paramPath = XPath.newInstance( "//param ");
List param = paramPath.selectNodes(doc);
Iterator i = param.iterator();
while (i.hasNext()) {
Element servlet = (Element) i.next();
String paramname=servlet.getChild( "param-name ").getTextTrim();
if (paramname.equals( "SYSTEM_SMTP ")){
out.print(servlet.getChild( "param-value ").getTextTrim()+ "aa ");
}else if(paramname.equals( "SYSTEM_USER ")){
out.print(servlet.getChild( "param-value ").getTextTrim()+ "bb ");
}
}
}
}