日期:2014-05-18  浏览次数:20620 次

在线等:servlet显示FTP的图片
求大神帮忙解决 


jsp展示图片,url指向servlet展示图片 ,图片在ftp上 

用到ftpClent类


我则呢吗也展示不出来,望路过大神指点小弟一下

------解决方案--------------------
apache common-net包直接读取ftp上出来的图片流替换servlet中的流



import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;


import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.Picture;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


/**
 * Servlet implementation class ShowPic
 */
@WebServlet("/ShowPic.slt")
public class ShowPicServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

private IdentityService identityService;

/**
 * @see HttpServlet#HttpServlet()
 */
public ShowPicServlet() {
super();
}


/*
 * (非 Javadoc)
 * 
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest,
 * javax.servlet.ServletResponse)
 */
@Override
public void service(ServletRequest request, ServletResponse response)
throws ServletExceptionIOException {

//通过spring配置初始化服务对象
ServletContext application = getServletContext();  
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);// 获取spring的context  
identityService = (IdentityService)wac.getBean("identityService");

Subject currentUser = SecurityUtils.getSubject();
Picture userPicture = identityService.getUserPicture(currentUser.getPrincipal().toString());