Tag: filenotfoundexception实时path

通过getRealPath()将上载文件写入磁盘时出现java.io.FileNotFoundException

Glassfish似乎增加了额外的path我想保存我的图像文件也有一些方法来使用只有绝对path我的servlet获得 String appPath = request.getServletContext().getRealPath(""); ? 我花了几天的时间尝试不同的方法来上传图像文件,并让一个servlet将其保存到磁盘。 我用这个例子: http : //www.codejava.net/java-ee/servlet/how-to-write-upload-file-servlet-with-servlet-30-api 使用debugging我可以看到文件名和path信息被正确收集,但代码在`part.write(savePath + File.separator + fileName)失败;“ 而glassfish的例外报告是: exception java.io.FileNotFoundException: C:\Program Files\glassfish-3.1.2.2\glassfish\domains\domain1\generated\jsp\com.onemore_onemore-web_war_1.0-SNAPSHOT\D:\Dropbox\Git\Brian_JEE\onemore\onemore\onemore-web\target\onemore-web-1.0-SNAPSHOT\image\screengrab_all_products.jpg (The filename, directory name, or volume label syntax is incorrect) 我可以看到正确的path作为这个exception的一部分D:\Dropbox\Git\Brian_JEE\onemore\onemore\onemore-web\target\onemore-web-1.0-SNAPSHOT\image\screengrab_all_products.jpg JSP <form action="${pageContext.request.contextPath}/imageupload" method="post" enctype="multipart/form-data" name="productForm" id="productForm"> <input type="file" name="file" id="file"> <input type="submit" name="Submit" value="Submit"></td> </form> Servlet的 @WebServlet(name = "UploadImageServlet", urlPatterns = {"/imageupload"}) […]