Part part = request.getPart("file");
if (part != null){
String fileName = extractFileName(part);
String filePath = savePath + File.separator + fileName;
part.write(savePath + File.separator + fileName);
String imageName = fileName;
} else{
String fileName = "avatar.jpg";
String filePath = savePath + File.separator + fileName;
part.write(savePath + File.separator + fileName);
String imageName = fileName;
}
在代码中插入 if else 语句后,我在底部的代码收到此错误消息:无法将 imageName 解析为变量,并且无法将 filePath 解析为变量。但是,一旦我注释掉我的 if else 语句,一切都很好。有人可以告诉我错误在哪里吗?
request.setAttribute("Pic", filePath);
request.setAttribute("PicName", imageName);