获取ftp图片

 前台请求:(用到ExtJs)

var imgPanel = new Ext.Panel({
	frame:true,
	region:'north',
	html:"<img  id='image' src='"+path+"/ScmCheck/displayImage.json?&custId =' style='width:800;height:1200;' />",
	autoScroll:true,
	bodyStyle:'text-align:center',
	height:Ext.getBody().getHeight()/2
});

 

 ftp辅助类(端口、用户名、密码、地址)

public class Constants {
        /**
	 * ftp设置
	 */
	public static final int FTPPORT = 21;
	public static final String FTPUSER = "ftpuser";
	public static final String FTPPSWD = "ftp0887*itd";
	public static final String IMAGE_FTP_URL = "ftp://ftpuser:ftp0887*itd@";
	public static final String IMAGE_FTP_PATH = "ibm.com//uploadPictures/201108/";
	public static final String IMAGE_FTP_URL_SYSCODE = "1.9.14.1";
	public static final String IMAGE_FTP_URL_DEFAULT_IMAGE_SYSCODE = "1.9.14.2";
}

 

后台获取ftp图片并返回显示:

public void displayImage(String custId,String checkTurn,HttpServletResponse response,ModelMap modelMap)
 throws Exception{
	try{
			
	         //ftp服务器地址
		SysCode ftp = this.sysCodeService.getById(Constants.IMAGE_FTP_URL_SYSCODE);//		
		String path = ftp.getDsc1();//
		String imageName = check.getId()+".jpg";
		String contentType = "image/jpeg;charset=GBK";
		//String type = "image/gif;charset=GB2312";
		path = path+imageName;
		OutputStream outputStream = response.getOutputStream();  
		URL u=new URL(path);
		InputStream in= u.openStream();
		byte tmp[] = new byte[10000];
		int s=0;
		while ((s = in.read(tmp)) != -1) {
		      outputStream.write(tmp, 0, s);
		}
		in.close();
		response.setContentType(contentType);
		outputStream.flush();
		outputStream.close();
	}catch(Exception e){
	         //ftp服务器默认图片地址
	          String path = ftp.getDsc1();
	        String contentType = "image/jpeg;charset=GBK";
	        path = path+imgName.getDsc1();
	        OutputStream outputStream = response.getOutputStream();  
	        URL u=new URL(path);
	        InputStream in= u.openStream();
	        byte tmp[] = new byte[10000];
	        int s=0;
	        while ((s = in.read(tmp)) != -1) {
	       	    outputStream.write(tmp, 0, s);
	        }
	        in.close();
	        response.setContentType(contentType);
	        outputStream.flush();
	        outputStream.close();
	        e.printStackTrace();
	}
}



 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值