jsp
<%-- <c:choose> --%>
<%-- <c:when test="${not empty oaUserinfo.headpicturename || not empty oaUserinfo.picturename}"> --%>
<img alt="头像" style="float: left; border-radius:10px;"
src=‘${contextPath }/oa/oaUserinfo!showImage.do?usercode=${oaUserinfo.usercode}‘
width="45px" height="45px" />
<%-- </c:when> --%>
<%-- <c:otherwise> --%>
<!-- <img style="width: 45px; height: 45px" -->
<%-- src=‘${ctx}/themes/blue/images/bbsheadpicturename.png‘ /> --%>
<%-- </c:otherwise> --%>
<%-- </c:choose> --%>
/**
* 页面显示图片
*
* @return
* @throws Exception
*/
public String showImage() throws Exception {
OaUserinfo info=baseEntityManager.getObjectById(object.getUsercode());
HttpServletResponse response = ServletActionContext.getResponse();
ServletOutputStream out = null;
// 页面上需要显示正式照片与否的参数
String userPicture = request.getParameter("userPicture");
try {
response.setContentType("application/octet-stream");
out = response.getOutputStream();
//人员上传头像时从数据库读取
byte[] b=null;
if ("1".equals(userPicture)) {
b=info.getPictureim();
} else if ("0".equals(userPicture)) {
b=info.getHeadpicture();
} else {
if ("1".equals(info.getIsusepicture())) {
b=info.getPictureim();
} else {
b=info.getHeadpicture();
}
}
//否则使用默认头像
if(null == b){
//D:\oa.home\wtpwebapps\xjoa\ (项目路径)
String basePath = request.getSession().getServletContext().getRealPath("/");
//themes/blue/images/bbsheadpicturename.png
File file= new File(basePath+CodeRepositoryUtil.getDataPiece("SYSPARAM", "DefaultImage"));
FileInputStream fis = new FileInputStream(file);
if (fis != null) {
int len = fis.available();
b = new byte[len];
fis.read(b);
}
}
out.write(b);
out.flush();
} catch (Exception e) {
} finally {
try {
if (null != out)
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}