JSP操作XML,删除节点问题
程序:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
path = application.getRealPath( "/ ");
Document doc = db.parse(path+ "left\\XML\\top.xml ");
NodeList nl = doc.getElementsByTagName( "Tree ");
nl.item(0).removeChild(doc.getElementById( "msdn "));
报错:
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:339)
org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:326)
org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:224)
org.apache.jsp.left.XML.deeptree_jsp._jspService(org.apache.jsp.left.XML.deeptree_jsp:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
------解决方案--------------------空指针错误,你得到的节点数据不存在吧?
------解决方案--------------------空指针:你这句话能定位到top.xml上吗:Document doc = db.parse(path+ "left\\XML\\top.xml ");
看看path+ "left\\XML\\top.xml这个路径是不是你的top.xml的相对路径.
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html