使用apachecommons在jsp中上传文件
我正在尝试使用ApacheCommonsFileUpload在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 {
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”
TOString filePath=request.getContextPath()+“/pics/”代码>希望对您有所帮助。。
String filePath=request.getContextPath()+File.separator+"pics"+File.separator;