Servlet_ResponseHeader

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        
        /*
         * 输出一个excel
         * */
        response.setContentType("application/vnd.ms-excel");
        PrintWriter out = response.getWriter();
        out.println("\tQ1\tQ2\tQ3\tQ4\tTotal");
        out.println("Apples\t90\t40\t49\t55");
        out.println("Oranges\t90\t40\t49\t55");
    }

返回一个excel表格

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("image/jpeg");
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("t.jpg");
        byte[] b = new byte[in.available()];
        in.read(b);
        OutputStream out = response.getOutputStream();
        out.write(b);
        out.close();
        in.close();
        
    }

显示一张图片

 

posted @ 2016-05-24 13:39  式微胡不归  阅读(244)  评论(0编辑  收藏  举报