首页 > 其他 > 详细

显示图片

时间:2017-03-13 12:39:01      阅读:130      评论:0      收藏:0      [点我收藏+]
	@SKS_Annotation(cmd = "getCapByNpId")
	public static void SKS_getCapByNpId(SkSession session, Np req, SkResponse res) {
		String capPath = null;
		String filename = null;
		if(req == null || req.getId() == null || "".equals(req.getId())){
			return;
		}
		FileInputStream fis = null;
		OutputStream out = null;
		try{
			capPath = PropertyUtils.getProperty("capPath");
			filename = req.getId() + ".jpg";
		    res.setContentType("application/octet-stream");
		    File file = new File(capPath + filename);
		    if(!file.exists()){
		    	file = new File(capPath + "404.png");
		    	if(!file.exists()){
		    		return;
		    	}
		    	res.setHeader("Content-disposition", "attachment;filename=404.png");
		    }else{
		    	res.setHeader("Content-disposition", "attachment;filename=" + filename);
		    }
		    fis = new FileInputStream(file);
		    int fileLength = fis.available(); // 得到文件大小
		    byte data[] = new byte[fileLength];
		    fis.read(data);
		    out = res.getOutputStream();
		    out.write(data);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(fis != null ){
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				} 
			}
			if(out != null){
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
	}

  

显示图片

原文:http://www.cnblogs.com/pureEve/p/6541788.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!