我在 servlet 的 init() 方法中初始化了一个 Document 对象,并在 doPost() 方法中使用它来为请求提供服务。
当 servlet 同时服务多个请求时,selectNodeList() xpath 查询会给出异常。异常如下所示:
Caused by: javax.xml.transform.TransformerException: -1
at org.apache.xpath.XPath.execute(XPath.java:331)
at org.apache.xpath.CachedXPathAPI.eval(CachedXPathAPI.java:328)
at org.apache.xpath.CachedXPathAPI.selectNodeList(CachedXPathAPI.java:255)
at org.apache.xpath.CachedXPathAPI.selectNodeList(CachedXPathAPI.java:235)
at com.pro.bb.servlets.Controller.getDataOrPeriodForReport(Controller.java:511)
... 23 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
at org.apache.xpath.XPathContext.pushCurrentNode(XPathContext.java:808)
at org.apache.xpath.axes.PredicatedNodeTest.acceptNode(PredicatedNodeTest.java:447)
at org.apache.xpath.axes.AxesWalker.nextNode(AxesWalker.java:409)
at org.apache.xpath.axes.WalkingIterator.nextNode(WalkingIterator.java:176)
at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:320)
at org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:474)
at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:257)
at org.apache.xpath.axes.LocPathIterator.execute(LocPathIterator.java:257)
at org.apache.xpath.XPath.execute(XPath.java:308)
帮我解决问题。