[英]variable from parameter @PUT in web service correct?
Is this correct? 这个对吗?
I want to get variable from @PUT method parameter in REST web service. 我想从REST Web服务中的@PUT方法参数获取变量。
But I get the variable "Null" , how to get parameter? 但我得到变量“Null”,如何获取参数?
Could anyone tell me? 有谁能告诉我?
@PUT
@Produces("application/html")
public Response postContainer(@PathParam("objecturi")String path){
mongoDAOImpl impl=new mongoDAOImpl();
Mongo mongo=impl.getConnection("127.0.0.1","27017");
DB db=impl.getDataBase(mongo,"public");
DBCollection coll=impl.getColl(db,"public");
mongoDTO dto=new mongoDTO();
dto.setParentpath("/home/public/liren");
dto.setUserName("liren");
dto.setPassWord("liren");
dto.setFileName(path);
dto.setAbsolutepath(dto.getParentpath()+"/"+dto.getFileName());
boolean bool;
try{
file= new filemethods();
bool=file.createcontainers(coll, dto, path);
if(bool==true){
return Response.status(Response.Status.OK).build();
}else {
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
}catch(Exception ex){
return Response.status(Response.Status.BAD_REQUEST).tag("Container create error"+ex.toString()).build();
}
Is your method parameter an http parameter like /uri?objecturi=/some/path? 你的方法参数是一个http参数,比如/ uri?objecturi = / some / path? Then you have to use @QueryParam("objecturi") instead of @PathParam("objecturi").
然后你必须使用@QueryParam(“objecturi”)而不是@PathParam(“objecturi”)。
What do you have in your @Path
annotation? 你的
@Path
注释有什么用? Basically if you want your code to work, you must have something like @Path("/url/{objecturi}")
基本上如果你想让你的代码工作,你必须有类似
@Path("/url/{objecturi}")
For HTTP PUT-method you need to use form parameters with "application/x-www-form-urlencoded" MIME-type of your HTTP Header and @QueryParam annotation. 对于HTTP PUT方法,您需要将表单参数与HTTP标头的“application / x-www-form-urlencoded”MIME类型和@QueryParam注释一起使用。
@PUT
@Produces("application/html")
@Consumes("application/x-www-form-urlencoded")
public Response postContainer(@QueryParam("objecturi")String path){
...
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.