2
  1. List item

How can I get the header information from HttpServletResponse?

Krishna Kumar Chourasiya
  • 2,030
  • 3
  • 20
  • 23
  • http://stackoverflow.com/questions/9172064/how-i-can-i-get-header-from-response-as-servletresponse-getheaderstring-is-n – RaceBase Aug 28 '13 at 10:53
  • This question should never have achieved such a high ranking on google, 4 years later. – Adam Dec 18 '17 at 13:02

4 Answers4

4

There is a method in that getHeader()

Note:Available only for servelt 3.0,If not you can't use this.

and

This method considers only response headers set or added via setHeader(java.lang.String, java.lang.String), addHeader(java.lang.String, java.lang.String), setDateHeader(java.lang.String, long), addDateHeader(java.lang.String, long), setIntHeader(java.lang.String, int), or addIntHeader(java.lang.String, int), respectively.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • Thanks Suresh. I have added maven dependency javax.servlet Version 3.1 now I am able to resolve compilation error on JSP, but I am not able to get HttpServletResponse and HttpServletRequest object in controller. I am using Spring Spring MVC annotation based – Krishna Kumar Chourasiya Aug 28 '13 at 11:07
  • @KrishnaKumar I am not much aware of Spring: You need make some changes in your method signature I guess see here :http://stackoverflow.com/questions/8504258/spring-3-mvc-accessing-httprequest-from-controller – Suresh Atta Aug 28 '13 at 12:01
1

HttpServletResponse.getHeader("key") returns first value

HttpServletResponse.getHeaders("key) return all values belonging to this key.

yunus kula
  • 859
  • 3
  • 10
  • 31
0

The HttpServletResponse.getHeaders method is almost certainly what you want to use.

arthegall
  • 36
  • 2
0

HttpServletResponse#getHeaders(java.lang.String) returns you a list of all headers for that string value

Philipp Sander
  • 10,139
  • 6
  • 45
  • 78
  • Hi Philipp, getting compilation error when using <% response.getHeader("Author"); %> May this is because of I am using maven dependency javax.servlet - version 2.5 – Krishna Kumar Chourasiya Aug 28 '13 at 11:03