How to get header from response in Servlet 2.3 or 2.5

jakarta-ee, java, servlet-2.5, servlet-filters, servlets

Solution

You cannot get the header from the stream*.

What you have to do is insert a proxy response object into the filter chain before your Servlet is called, and have that capture the header.

* Actually, you could potentially capture stuff from the stream using a proxy response and decode the headers. But if you are inserting a proxy response, it is simpler to capture the headers directly.

Problem

I know that v3.0 has method `getHeader()` but what about 2.3? Maybe it possible to get from steam? UPDATE: Actually, I need the HTTP response header RESTful application. In some reason I have decided to do this in servlet filter... but without success... Solution `@javax.ws.rs.core.Context HttpHeaders requestHeaders`. For example, ``` @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 in will help for someone. But any case, for Servlet issue still is opened

Original source

Related problems