我正在尝试检索存储在我的 tomcat 服务器中的图片,并且我想在我的网页中显示这些图片,但我不知道如何访问或访问它们。 那我该怎么做
// upload code from my netbeans project
File f = new File("images/" + name + ".png");
OutputStream outputStream = new FileOutputStream(f);
int read;
byte[] bytes = new byte[1024];
while ((read = inp.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
jsp page <img src="?">
最佳答案
- 你不应该上传到“当前目录”,例如tomcat 的 bin 目录(正如您在对其他答案的评论中提到的)
- 在磁盘的其他位置选择合适的位置
- 查看如何编写 DownloadServlet。该 servlet 可以传送上传的内容,例如在
http://example.com/image/FILENAME.jpg
- 查找“路径遍历”,这样你就不会让自己容易受到这种类型的攻击:
http://example.com/image/../../../../等/密码
关于java - 访问我已上传到 tomcat 服务器的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36933275/