【发布时间】:2018-12-25 22:01:06
【问题描述】:
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public @ResponseBody String uploadFileHandler(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
String name=file.getOriginalFilename();
try {
byte[] bytes = file.getBytes();
// Creating the directory to store file
String rootPath = System.getProperty("catalina.home");
File dir = new File(rootPath + File.separator + "tmpFiles");
if (!dir.exists())
dir.mkdirs();
// Create the file on server
File serverFile = new File(dir.getAbsolutePath() + File.separator +name );
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();
return "You successfully uploaded file=" + name;
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload because the file was empty.";
}
}
我已将文档上传到服务器文件夹,我想显示我已上传的所有文档。
【问题讨论】:
-
你自己试过了吗?如果是这样,您能否向我们展示一些您如何尝试执行此操作的代码?
-
我已经分享了我用过的代码。
-
此代码并未显示任何实际列出文件的尝试,它是您的上传代码。
-
是的,但我想知道我该怎么做,当我选择任何文档时,它应该显示在 jsp iframe 中。
-
所以您甚至没有尝试自己研究这个问题,您只是决定立即寻求答案?
标签: javascript spring jsp