2016-04-29 32 views
-1

我試圖檢索圖片,我已經存儲在我的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

回答

0
  • 你不應該上傳到 「當前目錄」,例如tomcat的bin目錄(如你在其他答案的評論中提到的那樣)
  • 在磁盤上其他地方選擇一個合適的位置
  • 查看如何編寫DownloadServlet。該servlet可以傳送上傳的內容,例如在http://example.com/image/FILENAME.jpg
  • 查找「路徑遍歷」,讓你不要使自己容易受到這種類型的攻擊:http://example.com/image/../../../../etc/passwd