【发布时间】:2015-09-29 15:51:52
【问题描述】:
我目前在 Tomcat 7 服务器上有一个 Java Web 应用程序,它应该生成文件并将它们保存在用户指定的路径上。当我在本地机器上测试它时,这工作正常,但是当我部署到开发服务器时,文件保存在服务器上的以下路径“conf/Catalina/localhost”中,指定路径作为名称的一部分。
例如,如果我将目录设置为我希望将文件保存到“C:\Users\kbbj\Desktop”的位置,则文件将在服务器上保存为“C:\Users\kbbj\Desktop\filename.txt”。分机”。
这是我创建 Word 文件的代码(注意它保存的最后一部分):
public static void createWordDoc(Request request) throws Docx4JException {
String filename = request.study+"_data_specs_v"+request.currentVersion+".docx";
wordMLPackage = WordprocessingMLPackage.createPackage();
//Create titles
String title = request.study+" Data Specifications v."+request.currentVersion;
String subtitle = request.analysis.analysisType+" Analysis for "+request.purpose.purpose;
// Add titles to document
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Title",title);
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Subtitle",subtitle);
wordMLPackage.getMainDocumentPart().addParagraphOfText("");
wordMLPackage.getMainDocumentPart().addParagraphOfText("");
//Create specification table
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Heading2", "Specifications");
factory = Context.getWmlObjectFactory();
Tbl table = factory.createTbl();
Tr tableRow = factory.createTr();
addStyledTableCell(tableRow, "Variable Name",true,null);
addStyledTableCell(tableRow, "Values",true,null);
addStyledTableCell(tableRow, "Method",true,null);
addStyledTableCell(tableRow, "Analyst Instructions",true,null);
table.getContent().add(tableRow);
System.out.println("Number of specs: "+request.specs.size());
//Add specs to table
for(Specification spec:request.specs){
Tr newRow = factory.createTr();
addTableCell(newRow, spec.variable.name!=null ? spec.variable.name : "");
addTableCell(newRow, spec.variable.codeList!=null ? spec.variable.getCodeListAsString():"");
addTableCell(newRow, spec.method!=null ? spec.method.method:"");
addTableCell(newRow, spec.instructions!=null ? spec.instructions:"");
table.getContent().add(newRow);
}
wordMLPackage.getMainDocumentPart().addObject(table);
//Save the file on project directory
String filepath = request.directory+"\\"+filename;
System.out.println("file path: "+filepath);
wordMLPackage.save(new java.io.File(filepath));
}
有什么想法吗?
感谢您的帮助!
【问题讨论】: