Web 服务中参数 @PUT 的变量正确吗?
这是正确的吗?
我想从 REST Web 服务中的 @PUT 方法参数获取变量。
但是我得到了变量“Null”,如何获取参数?
谁能告诉我吗?
@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 this correct?
I want to get variable from @PUT method parameter in REST web service.
But I get the variable "Null" , how to get parameter?
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的方法参数是像/uri?objecturi=/some/path这样的http参数吗?然后你必须使用@QueryParam(“objecturi”)而不是@PathParam(“objecturi”)。
Is your method parameter an http parameter like /uri?objecturi=/some/path? Then you have to use @QueryParam("objecturi") instead of @PathParam("objecturi").
您的
@Path
注释中有什么?基本上,如果您希望代码正常工作,则必须具有类似
@Path("/url/{objecturi}")
What do you have in your
@Path
annotation?Basically if you want your code to work, you must have something like
@Path("/url/{objecturi}")
对于 HTTP PUT 方法,您需要使用带有“application/x-www-form-urlencoded”MIME 类型的 HTTP 标头和 @QueryParam 注释的表单参数。
希望这有帮助。
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.
Hope this helps.