The sytax of addXXX and setXXX is excatly the same.
See below:
doGet(req, res){
res.setHeader("content_type", "text/html");
res.setIntHeader("content_length", 1029);
res.setDateHeader("last-modified", 100000000);
}
Note, here, we all use setHeader, becoz this header data may already exists for default. If you use addHeader, it may not effect.
Normally, we use setHeader instead of addHeader in response .
doGet(req, res){
req.addHeader("accept_type", "image/gif, image/jpeg");
req.getRequestDispatcher("newServlet").forward(req, res);
}
Here I use addHeader for the accept_type of request, becoz an accept type may already exists for the request, I don't want to overwrite it, so add it. and Forward it to a new
servlet, the new servlet may can return a image/gif or image/jpeg.