【问题标题】:File upload in jsp using Apache commons使用 Apache commons 在 jsp 中上传文件
【发布时间】:2013-09-29 16:53:25
【问题描述】:

我正在尝试使用 Apache commons fileupload 在 jsp 中上传文件。我目前使用的代码是:

String filePath=request.getContextPath()+"pics";
if (fileName.lastIndexOf("\\") >= 0) 
     {
           file = new File(filePath+fileName.substring(fileName.lastIndexOf("\\")));
     } else {
          file = new File(filePath+ fileName.substring(fileName.lastIndexOf("\\")+ 1));
             }
                            fi1.write(file);

我在指定此文件的路径时感到困惑。如果我使用这条路径,一切都会很好:

String filePath="C:\\Users\\Somye\\Documents\\NetBeansProjects\\A.K\\web\\pics\\";

但我的需要是使用 request.getContextPath();
有什么办法吗??

【问题讨论】:

  • 更改:String filePath=request.getContextPath()+"pics"; TO String filePath=request.getContextPath()+"/pics/"; 希望对您有所帮助..

标签: jsp file-upload


【解决方案1】:

改变

String filePath=request.getContextPath()+"pics";

String filePath=request.getContextPath()+File.separator+"pics"+File.separator;

【讨论】:

    猜你喜欢
    • 2010-11-11
    • 2011-08-18
    • 1970-01-01
    • 2013-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    • 2015-12-23
    相关资源
    最近更新 更多