dom4j selectSingleNode方法返回为null
下面一段代码用于取出web.xml中的session-timeout元素的值,我调用了dom4j的selectSingleNode方法,但是返回的值总是null,请大家帮我看看错在哪里?
public HashMap getSessionTimeOut(String fileName)throws MalformedURLException,
DocumentException
{
HashMap map=new HashMap();
try
{
Document document = read(fileName);
Node node=document.selectSingleNode("//session-timeout");
map.put("session-timeout", node.getText());
}
catch (DocumentException e)
{
System.out.println(e.getMessage());
}
catch (IOException es)
{
System.out.println(es.getMessage());
}
catch(Exception ee)
{
ee.printStackTrace();
}
return map;
}
document 的值肯定不为null,这个我已经跟踪过。我再web.xml中设置了这个元素:
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
每次总说node为null,不知道为什么
public HashMap getSessionTimeOut(String fileName)throws MalformedURLException,
DocumentException
{
HashMap map=new HashMap();
try
{
Document document = read(fileName);
Node node=document.selectSingleNode("//session-timeout");
map.put("session-timeout", node.getText());
}
catch (DocumentException e)
{
System.out.println(e.getMessage());
}
catch (IOException es)
{
System.out.println(es.getMessage());
}
catch(Exception ee)
{
ee.printStackTrace();
}
return map;
}
document 的值肯定不为null,这个我已经跟踪过。我再web.xml中设置了这个元素:
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
每次总说node为null,不知道为什么
...全文
相关推荐
在dom4j中使用XPath的简单实例
下面小编就为大家带来一篇在dom4j中使用XPath的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
DOM4J_xpath
详细介绍dom4j_xpath,相信对想学dom4j_xpath的朋友有帮助
DOM4J 读取xml字符串
NULL 博文链接:https://navylee.iteye.com/blog/727103
dom4j解析xml
使用dom4j对xml文档进行增删改. 查询就不用说了,使用elements(....)/element(...)/attributeValue()/getText()等方法
java Dom4j 无敌连环解析XML工具类
java Dom4j 无敌连环解析XML工具类


Web 开发
