【发布时间】:2017-05-04 17:33:23
【问题描述】:
我正在尝试来自此 URL http://afewdoubts.blogspot.com/2013/03/upload-fileimage-in-folder-using-servlet.html 的代码,但它会将图像保存到 NetBeans 临时文件夹 C:\Users\user\AppData\Roaming\NetBeans\8.1\config\GF_4.1.1\domain1\generated\jsp\WebApplication,而不是将其保存到指定的路径。
这是我尝试编辑的代码
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);
感谢您的帮助。 谢谢
【问题讨论】:
标签: jsp servlets file-upload netbeans glassfish