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;
}
After inserting the if else statement into the code, my code at the bottom gotten this error saying: imageName cannot be resolved to a variable and filePath cannot be resolved to a variabl. However, once i comment away my if else statement everything is fine. Can someone tell me where is the error?
request.setAttribute("Pic", filePath);
request.setAttribute("PicName", imageName);