restful webservices @DELETE 405错误

时间:2016-12-26 20:19:53

标签: java rest jaxb

我有这段代码来删除具有特定ID的播放器:

    @DELETE
    @Produces(MediaType.APPLICATION_XML)
    @Path("/delPlayer/{pid}")
    public int deleteById(@PathParam("pid") Integer pid){
        TypedQuery<Player> q = em.createQuery("DELETE p FROM Player p WHERE p.pid = :c", Player.class);
return q.setParameter("c", pid).executeUpdate();
    }

当我在浏览器中打开http://localhost:8080/Project/r/Player/delPlayer/100时,我得到了

HTTP Status 405 - Method Not Allowed
type Status report
messageMethod Not Allowed
descriptionThe specified HTTP method is not allowed for the requested resource.

1 个答案:

答案 0 :(得分:0)

您无法使用浏览器打开该方法,因为浏览器将使用GET而不是DELETE打开URL。您应该使用正确的动词创建一个简单的方法来调用它,或者您也可以使用cURL调用它来自unix shell