[英]How to get header from response in Servlet 2.3 or 2.5
I know that v3.0 has method getHeader()
but what about 2.3? 我知道v3.0有方法
getHeader()
但是2.3怎么样? Maybe it possible to get from steam? 也许有可能从蒸汽中获得?
UPDATE: 更新:
Actually, I need the HTTP response header RESTful application. 实际上,我需要HTTP响应头RESTful应用程序。 In some reason I have decided to do this in servlet filter... but without success... Solution
@javax.ws.rs.core.Context HttpHeaders requestHeaders
. @javax.ws.rs.core.Context HttpHeaders requestHeaders
某种原因,我决定在servlet过滤器中执行此操作...但没有成功...解决方案@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
但无论如何,对于Servlet问题仍然是开放的
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. 您需要做的是在调用Servlet之前将代理响应对象插入到过滤器链中,然后捕获标头。
* 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.
但是,如果要插入代理响应,则直接捕获标头会更简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.