我正在使用servlet上传文件。它在Chrome中运行良好,但在Internet Explorer中不起作用。
http://www.technicalkeeda.com/servlet-jsp-tutorials/how-to-upload-file-using-servlet-jsp
尝试获取文件后,我收到以下错误。
/usr/local/lib/python2.7/dist-packages/scipy/optimize/minpack.py:604: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
它似乎是由正在设置的变量引起的。
这就是它在IE中的样子
java.io.FileNotFoundException: C:\Orion\default-web-app\IT\uploads\C:\Users\testUser\Desktop\MultiPartFilterServlett.java (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:417)
at com.itws.itwsPost.doPost(itwsPost.java:194)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:208)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:306)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:333)
at com.evermind._csb._pvd(Unknown Source)
at com.evermind._csb._boc(Unknown Source)
at com.evermind._ax._lsc(Unknown Source)
at com.evermind._ax._uab(Unknown Source)
at com.evermind._bf.run(Unknown Source)
这就是Chrome中的样子
Got path:C:\Orion\default-web-app\IT\uploads
Set UploadedFile:C:\Orion\default-web-app\IT\uploads\C:\Users\testUser\Desktop\Stored procedure executed from SQL server.docx
以下是查看文件时的作用。
Got path:C:\Orion\default-web-app\IT\uploads
Set UploadedFile:C:\Orion\default-web-app\IT\uploads\Combined SRS Sites.doc
答案 0 :(得分:0)
这是因为IE正在发送完整路径,而不仅仅是文件名。我添加了一些代码来从路径中获取名称并且它有效。仍可在Chrome中使用。
itemName = item.getName();
String fileName = new File(itemName).getName(); // Removes the path if imported from IE. Chrome was not affected by this.