服务器端J2EE Web服务获取参数的空值 [英] Server side J2EE Webservice gets null values on parameters
本文介绍了服务器端J2EE Web服务获取参数的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是J2ee的新手,我在这里做错了什么?我的参数获取了空值.
I am a newbie at J2ee, What am I doing wrong here ? I am getting null values for my parameters.
HTTP GET URL
HTTP GET URL
http://:8080/mypath?identity = abcd& identityType = 1
http://:8080/mypath?identity=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
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返回
Client println returns
http://:8080/mypath?identity = abcd& identityType = 1
http://:8080/mypath?identity=abcd&identityType=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) ;
这篇关于服务器端J2EE Web服务获取参数的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文