访问图像,我已经上传到tomcat服务器

问题描述:

我试图检索图片,我已经存储在我的tomcat服务器,并且我想要显示这些图像在我的网页,但我不怎么可以到达或访问它们。 所以我怎么可以让这个访问图像,我已经上传到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="?">

+0

图像存储在bin文件夹中的Tomcat服务器 – user3576884

  • 你不应该上传到 “当前目录”,例如tomcat的bin目录(如你在其他答案的评论中提到的那样)
  • 在磁盘上其他地方选择一个合适的位置
  • 查看如何编写DownloadServlet。该servlet可以传送上传的内容,例如在http://example.com/image/FILENAME.jpg
  • 查找“路径遍历”,让你不要使自己容易受到这种类型的攻击:http://example.com/image/../../../../etc/passwd