Web 服务中参数 @PUT 的变量正确吗?

发布于 2024-10-27 00:22:42 字数 1117 浏览 4 评论 0原文

这是正确的吗?

我想从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾听心声的旋律 2024-11-03 00:22:42

你的方法参数是像/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").

戏蝶舞 2024-11-03 00:22:42

您的 @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}")

¢蛋碎的人ぎ生 2024-11-03 00:22:42

对于 HTTP PUT 方法,您需要使用带有“application/x-www-form-urlencoded”MIME 类型的 HTTP 标头和 @QueryParam 注释的表单参数。

@PUT
@Produces("application/html")
@Consumes("application/x-www-form-urlencoded")
public Response postContainer(@QueryParam("objecturi")String path){
...
}

希望这有帮助。

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.

@PUT
@Produces("application/html")
@Consumes("application/x-www-form-urlencoded")
public Response postContainer(@QueryParam("objecturi")String path){
...
}

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文