zoukankan      html  css  js  c++  java
  • 显示图片

    	@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();
    				}
    			}
    		}
    		
    	}
    

      

  • 相关阅读:
    hdu 1551 恶心的卡精度题
    ubuntu下升级firefox
    清理windows垃圾
    hdu 1575 矩阵快速幂
    右键菜单中添加用记事本打开(转)
    hdu 1525 博弈
    PHP字符串函数(转)
    笔试注意事项
    .NET 2.0面向对象编程揭秘 继承
    李开复:21世纪7种人才最抢手
  • 原文地址:https://www.cnblogs.com/pureEve/p/6541788.html
Copyright © 2011-2022 走看看