1.关于响应头的一些基础设置
//设置相应头
response.addHeader("name","zhangsan");
response.addIntHeader("age",28);
response.addDateHeader("brithday", date.getTime());
response.addHeader("name","lisi");
2.set设置 覆盖前面相同的设置
response.setHeader("name", "wangwu");
3.结果
4.完整代码
package com.hdh.header; import java.io.IOException;
import java.sql.Date; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class HeaderServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Date date=new Date(0);
//设置相应头
response.addHeader("name","zhangsan");
response.addIntHeader("age",28);
response.addDateHeader("brithday", date.getTime());
response.addHeader("name","lisi"); //set设置 覆盖前面想同的设置
response.setHeader("name", "wangwu");
} protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
} }