前台请求:(用到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();
}
}