我是J2ee的新手,我在这里做错了什么?我的参数值为空值。
HTTP GET网址
的http://:8080 / mypath中同一性= ABCD&安培; identityType = 1
代码
@GET
@Path("Request")
@Consumes({ MediaType.TEXT_PLAIN })
public Response get(@PathParam("identity") String identity,
@PathParam("identityType") int identityType) {
System.out.println("Identity "+identity+" IdentityType "+identityType) ;
返回
Identity null IdentityType 0
客户端Junit代码
String phoneNumber = new String("abcd");
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
String authenticateService = "http://" + SERVER
+ "/mypath?";
List<NameValuePair> params = new LinkedList<NameValuePair>();
params.add(new BasicNameValuePair("identity", phoneNumber));
params.add(new BasicNameValuePair("identityType", String
.valueOf(1)));
String paramString = URLEncodedUtils.format(params, "utf-8");
authenticateService += paramString;
URI url = UriBuilder.fromUri(authenticateService).build();
WebResource service = client.resource(url);
System.out.println(authenticateService);
->Exception Here<- String identityHash = service.type(MediaType.TEXT_PLAIN).get(
String.class);
assertNotNull(identityHash);
客户端println返回
的http://:8080 / mypath中同一性= ABCD&安培; identityType = 1
答案 0 :(得分:1)
修正了此问题,将PathParam
替换为QueryParam
@GET
@Path("Request")
@Consumes({ MediaType.TEXT_PLAIN })
public Response get(@QueryParam("identity") String identity,
@QueryParam("identityType") int identityType) {
System.out.println("Identity "+identity+" IdentityType "+identityType) ;
答案 1 :(得分:0)
要使用PathParm
,您必须调整网址和方法定义
URL
代码
@Path("Request/{identity}/{identityType}")
public Response get(@PathParam("identity") String identity, @PathParam("identityType") int identityType)
此致