您的位置:首页 > 其它

文件预览

2016-03-21 15:15 162 查看
①JSP页面

<div class="aa"><img src=${previewImageSrc}/></div>
//${previewImageSrc},是访问路径 例如:/jxz-opr/viewFile?fileID=pl_17e184dfe63a46faae88ea254a99cd


②action

/**
* 预览图片
*
* @return
* @throws Exception
* @throws FileNotFoundException
*/
@Action("viewFile")
public String viewImages() throws Exception {
ServletOutputStream out = null;
FileInputStream in = new FileInputStream(fileSystem.getFile(getFileID()));
//fileSystem.getFile(getFileID())获取文件相当于new File("d:\\dst.txt")
getResponse().setContentType("multipart/form-data");
out = getResponse().getOutputStream();
int i=0;
byte tmp[] = new byte[4096];
while ((i = in.read(tmp)) != -1) {
out.write(tmp, 0, i);
}
out.flush();
in.close();
out.close();
return null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: