2017-05-04 79 views
0

我在嘗試使用此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而不是將其保存到指定的路徑。上傳圖像並使用JSP/Servlet將其保存到文件夾中

繼承人的代碼,我已經試過編輯

  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); 

您的幫助表示讚賞。 感謝

回答

相關問題