标签:style blog http io color java sp 文件 div
package readPic; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ReadPic extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException{ resp.setHeader("content-type","image/jpeg"); InputStream in=this.getServletContext().getResourceAsStream("1.jpg"); //1.jpg 放在WebRoot根目录下 int len=0; byte buffer[]=new byte[1024]; OutputStream out=resp.getOutputStream(); while( (len=in.read()) > 0){ out.write(buffer,0,len); } } }
标签:style blog http io color java sp 文件 div
原文地址:http://www.cnblogs.com/balfish/p/4074179.html