码迷,mamicode.com
首页 > 其他好文 > 详细

页面显示头像(图片)

时间:2015-06-02 21:24:02      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:

 

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;
}

页面显示头像(图片)

标签:

原文地址:http://www.cnblogs.com/liqiong88/p/4547498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!