Servlet响应头信息

1.输出excel表格

 1 package servlet_pack;
 2
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 /**
13  * Servlet implementation class PrintExcel
14  */
15 @WebServlet("/PrintExcel")
16 public class PrintExcel extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18
19     /**
20      * @see HttpServlet#HttpServlet()
21      */
22     public PrintExcel() {
23         super();
24     }
25
26     /**
27      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
28      */
29     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
30         response.setContentType("application/vnd.ms-excel");
31         PrintWriter out = response.getWriter();
32         out.println("\tQ1\tQ2\tQ3\tQ4\ttotal");
33         out.println("apple\t10\t20\t30\t40\t=sum(B2:E2)");
34         out.println("orange\t11\t22\t33\t44\t=sum(B3:E3)");
35     }
36
37     /**
38      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
39      */
40     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
41         doGet(request, response);
42     }
43
44 }

运行结果:

原文地址:https://www.cnblogs.com/ACGame/p/8452225.html

时间: 2024-08-28 08:39:52

Servlet响应头信息的相关文章

http响应头信息

HTTP 响应头信息 HTTP请求头提供了关于请求,响应或者其他的发送实体的信息. 在本章节中我们将具体来介绍HTTP响应头信息. 应答头 说明 Allow 服务器支持哪些请求方法(如GET.POST等). Content-Encoding 文档的编码(Encode)方法.只有在解码之后才可以得到Content-Type头指定的内容类型.利用gzip压缩文档能够显著地减少HTML文档的下载时间.Java的GZIPOutputStream可以很方便地进行gzip压缩,但只有Unix上的Netsca

wget/curl查看请求响应头信息

wget / curl 是两个比较方便的测试http功能的命令行工具,大多数情况下,测试http功能主要是查看请求响应 头信息 ,而给这两个工具加上适当的命令行参数即可轻易做到,其实查man手册就能找到对应的参数选项,不过这里仍然mark一下. wget --debug Turn on debug output, meaning various information important to the developers of Wget if it does not work properly

HTTP 响应头信息

HTTP 响应头信息 HTTP请求头提供了关于请求,响应或者其他的发送实体的信息. 在本章节中我们将具体来介绍HTTP响应头信息.

curl/wget 测试http请求的响应头信息

1. wget –debug wget可以使用debug信息来查看信息头,如下: [[email protected] ~]# wget --debug http://192.168.112.129/index.html DEBUG output created by Wget 1.12 on linux-gnu. --2017-06-01 10:15:12--  http://192.168.112.129/index.html Connecting to 192.168.112.129:80

Tomcat 中响应头信息(Http Response Header) Content-Length 和 Transfer-Encoding

户端(PC浏览器或者手机浏览器)在接受到Tomcat的响应的时候,头信息通常都会带上Content-Length ,一般情况下客户端会在接受完Content-Length长度的数据之后才会开始解析.而在Tomcat上,页面处理过程中会将需要out.print的数据都放在缓存中,然后一次性的返回给客户端. 另外一种情况就是头信息中不存在Content-Length ,取而代之的是Tansfer-Encoding:chunked ,这个头信息的的意思是response的内容会被Tomcat分成一块一

AFNetworking 2.0获取响应头信息

转载请注明出处:http://blog.csdn.net/dengbin9009/article/details/43304813 前文有提到在初始化的时候可以设置Http的头信息,这没有任何问题,但是在笔者使用过程中,时常是要获取Http返回的一些头信息,在初次用AFNetworking2.0新特性NSURLSessionDataTask的时候,为了获取返回的头信息,搞了两个晚上,先是度娘,谷歌,StackOverflow,然后各种那个群找人,嘴壶问同事找大神,最后都说没有用过.就在想要放弃,

Servlet请求头信息

java代码: 1 package servlet_pack; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.util.Enumeration; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpSer

http请求响应头信息

package aaa; import java.io.UnsupportedEncodingException;import java.nio.charset.Charset;import java.util.Arrays; import org.springframework.http.HttpEntity;import org.springframework.http.HttpHeaders;import org.springframework.http.HttpMethod;import

Android之Http通信——2.详解Http的消息头与响应头

Android之Http通信--2.详解Http的消息头 --转载请注明出处:coder-pig,请勿用于商业用途~ 本节引言: 在上一节中我们对HTTP的一些概念性的东西进行了了解:什么是HTTP协议,1.0版本与1.1版本的区别, SYN和ACK,TCP/IP三次握手,HTTP操作流程,几种不同的请求方式,HTTP的状态吗, 以及HTTP协议的特点,最后还了解了下OSI七层协议与TCP四层模型,相信大家对HTTP已经有了 简单的了解,本节我们来扣HTTP的消息头以及响应头,好了,开始本节内容