我有这段代码,它从通过 HttpServletRequest 请求传递的 URL 获取 XML 文件。我检查了非空/空的请求和 inStream 的值。但我收到错误“文档第 -1 行错误:文件过早结束。嵌套异常:文件过早结束。” request 和 inStream 值分别显示为 org.apache.catalina.connector.RequestFacade@34a7fc0 org.apache.catalina.connector.CoyoteInputStream@100917f0。以下是代码
private void processRequest(HttpServletRequest request,
HttpServletResponse response, VariablesSecureApp vars) {
// TODO Auto-generated method stub
try {
System.out.println(request);
InputStream inStream = request.getInputStream();
System.out.println(inStream);
SAXReader sax = new SAXReader();
Document doc = sax.read(inStream);
System.out.println(doc);
Element rootElement = (Element) doc.getRootElement();
if (!rootElement.getName().equals("ob")){
throw new OBException("The root element of the xml document should be: Ob but it is " + rootElement.getName());
}
//createSalesOrder(doc,response,request);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}