第一步:
在需要回显的地方加一个img 并加好id 如 <a href="#" onclick="uploadphoto()" ><img id="ppersonphoto" src="icasp/Style/wssb/xfrzp.gif" /></a>
打开时用window.open打开一个上传附件的网页,
window.open(tourl,diatitle,'status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=400');
第二步:
在点击上传之后紧接着在action里跳到保存成功页面,并把当前保存的这条信息的id传过去。
第三步:
在保存成功页面接收id并把第一步的页面中的img传入一个action地址
window.opener.document.getElementById("ppersonphoto").src="wssbperson.action?method=outimg&unid="+unid;
第四步:
传入之后在outimg这个action里接收到id去查出照片并通过流写出到第一步的img中 这样就达到了回显
public void outimg(HttpServletRequest req, HttpServletResponse res) throws Exception{
String unid=req.getParameter("unid");
WssbPersonphoto photo=commonService.get(WssbPersonphoto.class, unid);
BufferedInputStream inputImage = null;
try {
Blob blob =photo.getPphoto();
OutputStream out = res.getOutputStream();
inputImage = new BufferedInputStream(blob.getBinaryStream());
byte[] contents = new byte[1024];
int byteRead = 0;
String strFileContents;
while((byteRead = inputImage.read(contents)) != -1){
out.write(contents);
}
out.flush();
out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}