我使用这个链接文件上传文件上传。但是它给了我临时文件的位置。但是我想将我的应用程序文件夹存储在中。请分享您对此的看法。
发布于 2012-12-17 10:59:19
使用struts fileupload标记
<s:file name="fileUpload" id="fileUpload" />在行动课上
File fileUpload;
String fileUploadContentType;
String fileUploadFileName;
HttpServletRequest servletRequest;编写此方法在webcontent中创建/Upload/Document文件夹
private String saveDocumentDoc()
{
String filePath = servletRequest.getSession().getServletContext().getRealPath("/Upload/Document/");
System.out.println("Server Path "+filePath);
Date d = new Date();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Document");
String s=stringBuilder.toString();
File fileToCreate = new File(filePath, s);
try {
FileUtils.copyFile(this.fileUpload, fileToCreate);
} catch (IOException e) {
e.printStackTrace();
}
return s;
}希望它能帮你享受
https://stackoverflow.com/questions/13908591
复制相似问题