我自己制作了一個網站,該網頁上設定了插入圖片這一選項,可是當我插入一張名為
Peter_Jackson.jpg 的圖片後,網頁上沒有顯示,
而且myeclipse的console還報出了如下錯誤:
java.io.FileNotFoundException: C:\mysoftware\apache-tomcat-7.0.37\webapps\friend2\upload\pic_3\E:\David_Liu\picture\Peter_Jackson.jpg (文件名、目錄名或卷標語法不正確。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:221)
at java.io.FileOutputStream.(FileOutputStream.java:171)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:439)
at web.ActionServlet.service(ActionServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
C:\mysoftware\apache-tomcat-7.0.37\webapps\friend2\upload\pic_3\E:\David_Liu\picture\Peter_Jackson.jpg (文件名、目錄名或卷標語法不正確。)
很明顯,你存的是文件的完整磁盤路徑,在E盤下。其實你使用的文件名應該是服務器下上傳的文件。\E:\David_Liu\picture 這段刪除。Peter_Jackson.jpg 應該取你數據庫存的上傳的文件名