[英]variable from parameter @PUT in web service correct?
這個對嗎?
我想從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();
}
你的方法參數是一個http參數,比如/ uri?objecturi = / some / path? 然后你必須使用@QueryParam(“objecturi”)而不是@PathParam(“objecturi”)。
你的@Path
注釋有什么用? 基本上如果你想讓你的代碼工作,你必須有類似@Path("/url/{objecturi}")
對於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){
...
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.