1、后台代码
//显示本地磁盘图片
@RequestMapping("showPhoto")
public void showPhoto(HttpServletRequest request,HttpServletResponse response,
String strUrl) throws IOException{
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/jpeg"); //设置图片格式格式,这里可以忽略
String path = "D:/project/photoUpload/"+ strUrl ;
FileInputStream fis = new FileInputStream(path);
OutputStream os = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024*1024];
while ( (count = fis.read(buffer)) != -1 )
os.write(buffer, 0, count);
} catch (IOException e){
e.printStackTrace();
}finally {
if(os!=null)
os.close();
if(fis != null)
fis.close();
}
}
2、jsp代码
<div class="form-group controls">
<img alt="" src="${ctx}/employeeController/
showPhoto.do?strUrl=${employee.pictures}" style="width:150px;height:150px">
</div>