是否可以在JAX-RS下的REST方法中访问Request对象?
我刚刚发现了
@Context Request request;
答案 0 :(得分:55)
答案 1 :(得分:12)
详细说明@dfa对替代方案的回答,我发现这比在每个资源方法签名上指定变量更简单:
public class MyResource {
@Context
private HttpServletRequest httpRequest;
@GET
public Response foo() {
httpRequest.getContentType(); //or whatever else you want to do with it
}
}