我存储由用户上传的文件内容如下:用的Apache Tomcat在哪里存储上传的静态文件
InputStream inputStream = null;
OutputStream outputStream = null;
MultipartFile file = uploadedFile.getFile();
String fileName = file.getOriginalFilename();
String path ="C:/apache-tomcat-8.0.18/uploads/images/";
try {
inputStream = file.getInputStream();
File newFile = new File(path +fileName);
if (!newFile.exists()) {
System.out.println(newFile.getAbsolutePath());
newFile.createNewFile();
}
outputStream = new FileOutputStream(newFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
outputStream.close();
}
什么必须在上传的文件应当保存的路径?我想存储图像并将它们显示在JSP页面中。
我最初将文件存储在我的Maven项目的webapp/images文件夹中。但是,当应用程序重新部署时,上传的文件也将被删除。我怎么解决这个问题?
当我上传C:/apache-tomcat-8.0.18/uploads/images/我无法获取图像显示在我的JSP页面。获取错误不允许加载本地资源。
当你的JSP在浏览器中获取呈现,什么是对图像的HTML代码('')是什么样子? – manish