上传图片时,文件已成功保存并且路径已成功设置.但是在表单提交后不会立即显示上传的图像.仅当我重新加载页面时,才会显示上传的图像.
我正在保存上传的文件,如下所示:
InputStream is;
try {
File file = new File("C:\\****\\*****\\Documents\\NetBeansProjects\\EventsCalendary\\web\\resources\\images\\uploadPhoto.png");
is = event.getFile().getInputstream();
OutputStream os = new FileOutputStream(file);
setUserPhoto("\\EventsCalendary\\resources\\images\\"+file.getName());
byte buf[] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
is.close();
} catch (IOException ex) {
System.out.println(ex.getStackTrace());
}
Run Code Online (Sandbox Code Playgroud)
为什么上传的图像仅在重新加载页面后显示,我该如何解决?