<img width="50px" height="25px" src="<%=request.getContextPath()%>/CommController/showImg?imgpath=${sendOrderInfo.attmentpath}" alt="" />
后台代码:
@RequestMapping("showImg")
public void showImg(){
String imgPath = request.getParameter("imgpath");
File file=new File(imgPath);
if(file.exists()&&!"".equals(imgPath)){
try {
DataOutputStream dos=new DataOutputStream(response.getOutputStream());
DataInputStream dis=new DataInputStream(new FileInputStream(file.getAbsolutePath()));
byte[] data=new byte[2048];
while((dis.read(data))!=-1){
dos.write(data);
dos.flush();
}
dis.close();
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}