我有一个读取和写入数据的 servlet。这是我的代码片段
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
SPSSFile file = null;
try {
File f = new File(getServerDiretory() + "dabadeba_2011.01.03.sav");
if (!f.exists()) {
System.out.println("not found");
return;
}
file = new SPSSFile(f);
file.loadMetadata();
file.loadData();
if (file == null) {
System.err.println("vai");
return;
}
Document doc = file.getDDI2();
//set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "yes");
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
String xmlString = sw.toString();
writeToFile(xmlString);
out.println(xmlString);
} catch (TransformerException ex) {
Logger.getLogger(SPSSReaderServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(SPSSReaderServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (SPSSFileException ex) {
Logger.getLogger(SPSSReaderServlet.class.getName()).log(Level.SEVERE, null, ex);
} finally {
out.close();
if (file != null) {
file.close();
System.out.println("done, file closed");
}
}
}
一切似乎都在工作,直到我刷新 JSP 并再次调用这个 servlet。这是刷新页面后出现的错误:
SEVERE: org.opendatafoundation.data.spss.SPSSFileException: Error reading data: unexpected compression code for string variable
at org.opendatafoundation.data.spss.SPSSDataRecord.read(SPSSDataRecord.java:161)
at org.opendatafoundation.data.spss.SPSSDataRecord.read(SPSSDataRecord.java:54)
at org.opendatafoundation.data.spss.SPSSFile.loadData(SPSSFile.java:1277)
at ge.geostat.metadata.web.servlet.SPSSReaderServlet.processRequest(SPSSReaderServlet.java:63)
at ge.geostat.metadata.web.servlet.SPSSReaderServlet.doGet(SPSSReaderServlet.java:140)
当我重新部署应用程序并运行它时,它工作正常。我想这是一个内存问题,非常感谢任何帮助