How to get a header from a response in Servlet 2.3 or 2.5

I know v3.0 has a getHeader() method, but what about 2.3? Maybe you can get it from steam?

UPDATE:

Actually, I need a RESTful app for the HTTP response header. For some reason, I decided to do it in a servlet filter ... but without success ... Solution @javax.ws.rs.core.Context HttpHeaders requestHeaders .

For instance,

 @javax.ws.rs.GET public String invoceRestMethod(@Context HttpHeaders requestHeaders){ MultivaluedMap<String, String> map = headers.getRequestHeaders(); for (Map.Entry<String, List<String>> entry : map.entrySet()) { // processing header.... } } 

Maybe this will help someone. But in any case, the Servlet problem is still open

+4
source share
1 answer

You cannot get the header from the stream * .

What you need to do is insert the proxy response object into the filter chain before calling the servlet and grab the header.


* Actually, you could capture material from the stream using a proxy response and decode the headers. But if you insert a proxy response, it's easier to just write the headers.

+5
source

Source: https://habr.com/ru/post/1437803/