Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can i get header from response as ServletResponse().getHeader(string) is not visible?

Tags:

java

servlets

i have successfully set the httpServletResponse().setHeader("custtype", "permanent") but when i try to retrieve it httpServletResponse().getHeader("custtype") i do not see getheader method when i do control + soace in eclipse but as per doc at http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html its there. I am not sure why getHeader method is not visible here in eclipse.?

How i can i get header from response?

like image 473
M Sach Avatar asked Feb 07 '12 06:02

M Sach


People also ask

How do you add a response header in Java?

Setting Response Headers from Servlets The most general way to specify headers is to use the setHeader method of HttpServletResponse. This method takes two strings: the header name and the header value. As with setting status codes, you must specify headers before returning the actual document.

Can we set response header?

You can set response headers, you can add response headers But think about it for a second, then do this exercise. Draw a line from the HttpResponse method to the method's behavior. We did the most obvious one for you. Pretty obvious when you see them all together.

What is HttpServletResponseWrapper?

HttpServletResponseWrapper is one particular implementation of HttpServletResponse which gives you a convenient way to wrap an existing response with some logic of your own without having to write a whole new implementation of the interface.


1 Answers

getHeaders(...) methods HttpServletResponse are supported since Servlet 3.0., Before this version you can find only setHeader(...) methods.

For earlier version you can try wrapping the response and implement storing the headers in your wrapper class.

like image 90
Ramesh PVK Avatar answered Sep 18 '22 03:09

Ramesh PVK