Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用apachecommons在jsp中上传文件_Jsp_File Upload - Fatal编程技术网

使用apachecommons在jsp中上传文件

使用apachecommons在jsp中上传文件,jsp,file-upload,Jsp,File Upload,我正在尝试使用ApacheCommonsFileUpload在jsp中上传一个文件。我目前使用的代码是: String filePath=request.getContextPath()+"pics"; if (fileName.lastIndexOf("\\") >= 0) { file = new File(filePath+fileName.substring(fileName.lastIndexOf("\\"))); } else {

我正在尝试使用ApacheCommonsFileUpload在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";


更改:
stringfilepath=request.getContextPath()+“pics”
TO
String filePath=request.getContextPath()+“/pics/”希望对您有所帮助。。
String filePath=request.getContextPath()+File.separator+"pics"+File.separator;