java.io.FileNotFoundException: bg.jpg (系統找不到指定的檔案。)
at java.io.FileInputStream.open(Native Method)
at org.apache.jsp.ceshi.testimage_jsp._jspService(testimage_jsp.java:121)
程式碼使用相對路徑 new FileInputStream("bg.jpg"),**工作目錄不是 Web 應用根目錄**(通常是啟動腳本目錄或 bin),導致找不到檔案。
String realPath = getServletContext().getRealPath("/images/bg.jpg");FileInputStream fis = new FileInputStream(realPath);InputStream is = getServletContext().getResourceAsStream("/images/bg.jpg");new File("bg.jpg").getAbsolutePath(),確認 JVM 實際尋找的路徑。request.getPart()** 取得 InputStream 直接寫入 DB,避免落地臨時檔。BLOB / BYTEA,或存檔案系統只存路徑。