【发布时间】:2017-05-03 09:40:23
【问题描述】:
我正在使用 Jersey,我想从请求的标头中获取参数;
这是我的 java 服务器端代码:
@GET
@Path("/usersForMobile")
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response getUsersForMobile(@Context UriInfo info) {
String rashutId ;
String userName ;
String password;
List<User> inspectorList= new ArrayList<User>();
try {
rashutId = info.getQueryParameters().getFirst("rashutId");
userName = info.getQueryParameters().getFirst("userName");
password = info.getQueryParameters().getFirst("password");
inspectorList = LoginService.getInspectorsList(userName,password,rashutId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!inspectorList.isEmpty())
return Response.status(Status.OK).entity(new UsersResponse(inspectorList, true)).build();
else
return Response.status(Status.OK).entity("No inspectors found").build();
}
}
到目前为止,我是从 url 获取参数,但它不是可靠的方式,所以我决定将它们传递到 header 中,如何从请求 header 中获取它们?
谢谢!
【问题讨论】:
-
这与 Spring 有什么关系,您使用的是 JAX-RS (Jersey) ...
-
你说得对...对不起,我会编辑它。
-
你知道我的问题吗?
-
你没有使用 Spring MVC 中的任何东西...我建议阅读 Jersey 库以了解如何访问标头。
-
好的,你能编辑我的问题吗?非常感谢!!
标签: java server header jersey jax-rs