【问题标题】:Upload an image and save it to a folder using JSP/Servlet使用 JSP/Servlet 上传图像并将其保存到文件夹
【发布时间】: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


    【解决方案1】:

    此代码运行良好,但文件保存在 glassfish 临时文件夹中。如果可以的话,请帮助我File uploads using NetBeans and GlassFish Server

    结论:除了 glassfish 服务器或 netbeans 配置之外,代码没有任何问题。

    【讨论】:

      猜你喜欢
      • 2015-06-18
      • 2012-05-20
      • 2015-10-10
      • 2020-06-23
      • 2014-03-21
      • 2018-10-05
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      相关资源
      最近更新 更多