上传图像并使用JSP/Servlet将其保存到文件夹中



我正在尝试此URL http://afewdoubts.blogspot.com/2013/2013/upload-fileimage-in-folder-using-servlet.html图像NetBeans临时文件夹C:UsersuserAppDataRoamingNetBeans8.1configGF_4.1.1domain1generatedjspWebApplication,而不是将其保存到指定的路径。

这是我尝试编辑的代码

            PrintWriter out = response.getWriter();
            classclass c=new classclass();
            String savePath = File.separator + SAVE_DIR;
            File fileSaveDir=new File(savePath);
            String firstName=request.getParameter("firstname");
            String lastName=request.getParameter("lastname");
            Part part=request.getPart("file");
            String fileName=extractFileName(part);
            /*if you may have more than one files with same name then you can calculate some random characters and append that characters in fileName so that it will  make your each image name identical.*/
            part.write(savePath + File.separator + fileName);

感谢您的帮助。谢谢

此代码工作正常,但是将文件保存在玻璃鱼临时文件夹中。如果您可以使用NetBeans和Glassfish Server提交上传,请帮助我。

结论:除了Glassfish服务器或NetBeans配置外,代码没有错。

最新更新