我正在努力实现以下目标.
从Request中读取自定义标头及其值:
name: username
Run Code Online (Sandbox Code Playgroud)
现在,作为响应,我想name:value在HTTP响应中返回相同的标头对.
我正在使用JAX-RS webservice的Jersey 2.0实现.
当我发送请求URL时Http://localhost/test/,请求头也会被传递(暂时,虽然Firefox插件 - 硬编码).
收到该URL的请求后,将调用以下方法:
@GET
@Produces(MediaType.APPLICATION_JSON)
public UserClass getValues(@Context HttpHeaders header) {
MultivaluedMap<String, String> headerParams = header.getRequestHeaders();
String userKey = "name";
headerParams.get(userKey);
// ...
return user_object;
}
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这个目标?任何指针都会很棒!
我有以下结果类,其对象将作为JSON返回.
public class Result {
public String objectid;
public String dtype;
public String type;
public String name;
public String description;
public Result() {
this.objectid = "";
this.dtype= "";
this.type="";
this.name= "";
this.description = "";
}
public String getObjectid() {
return objectid;
}
public void setObjectid(String s) {
this.objectid = s;
}
public String getDtype() {
return dtype;
}
public void setDtype(String s) {
this.dtype= s;
}
public String getType() {
return type;
}
public void setType(String s) {
this.type = …Run Code Online (Sandbox Code Playgroud)