码迷,mamicode.com
首页 > Web开发 > 详细

【jsp】读取WebRoot下的图像文件

时间:2014-11-04 19:07:19      阅读:218      评论:0      收藏:0      [点我收藏+]

标签: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);
        }
    }
}

 

【jsp】读取WebRoot下的图像文件

标签:style   blog   http   io   color   java   sp   文件   div   

原文地址:http://www.cnblogs.com/balfish/p/4074179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!