PostReplaceFilter的问题,不能用PUT覆盖POST



我有问题与使用PostReplaceFilter。我试图覆盖一个POST请求从一个HTML表单发送一个PUT请求。文档说,对于Jersey 1.10(我正在使用),我只需要使用request HEADER("X-HTTP-Method-Override")查询参数"_method"来表示覆盖。我选择使用"_method"的方式,但它根本不起作用。

这是我的HTML表单:
<!DOCTYPE html>
<html>
    <head>
        <title>New comment</title>
    </head>
    <body>
        <form action="http://localhost:3030/booklet/clusters/4eec2b6c0364ddde9ad0a82a/comments/COMM5372363818493721528" method="POST">
          <input name="_method" type="hidden" value="PUT" />
          <TEXTAREA NAME="content" COLS=40 ROWS=6>"fafafdfdsgdsg"</TEXTAREA>
          <input type="submit" value="Update" />
        </form>
    </body>
</html>

这是我的资源:

@PUT
@Path("/{id}/comments/{comment_id}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void updateComment(
            @PathParam("id") String id,
            @PathParam("comment_id") String commentId,
            @FormParam("content") String content,
            @Context HttpServletResponse servletResponse
            ) throws IOException {
    Comment comment = new Comment();
    comment.setId(commentId);
    comment.setContent(content);        
    dao.updateOrCreateComment(comment);
    String requestURL = uriInfo.getBaseUriBuilder().build().toURL().toExternalForm() + 
            RESOURCE_CLUSTERS + "/" + id + "/" + 
            RESOURCE_COMMENTS;
    servletResponse.sendRedirect(requestURL);
}

这是我的web.xml配置:

 <init-param>
   <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
   <param-value>com.sun.jersey.api.container.filter.PostReplaceFilter;com.sun.jersey.api.container.filter.LoggingFilter</param-value>
 </init-param>
 <init-param>
   <param-name>com.sun.jersey.api.container.filter.PostReplaceFilterConfig</param-name>
   <param-value>QUERY</param-value>
 </init-param>

我也试过了:

<init-param>
   <param-name>com.sun.jersey.api.container.filter.PostReplaceFilterConfig</param-name>
   <param-value>HEADER,QUERY</param-value>
 </init-param>

我不知道哪里出了问题,但请求仍然显示为POST,而不是PUT,在服务器端。如果我错过了什么重要的东西,请告诉我。

谢谢各位,

您需要在查询参数中传递方法名称,而不是表单参数。即,而不是添加一个名为"_method"的隐藏输入到您的表单,添加"_method"查询参数到您的表单的操作URI。例如,动作URI应该是:http://localhost:3030/booklet/clusters/4eec2b6c0364ddde9ad0a82a/comments/COMM5372363818493721528?_method=PUT

最新更新