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(); }
显示一张图片