@PUT Jersey错误405:不允许使用方法

Apa*_*ant 1 java tomcat http put jersey

我正进入(状态

错误405:不允许方法

MessageEnd.java:

package com.example.wordcount;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/jersey")
public class MessageEnd {

    @GET
    @Path("/getvalue/{word}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response sayHello(@PathParam("word") String word){

        String output = " Count of word " + word;
        return Response.status(200).entity(output).build();
    }

    @PUT
    @Path("/sendvalue/{msg}")
    @Consumes(MediaType.TEXT_PLAIN)
    @Produces(MediaType.TEXT_PLAIN)
    public Response sendMsg(@PathParam("msg") String msg){

        String output = "Received message= " + msg;
        return Response.status(200).entity(output).build();
    }

}
Run Code Online (Sandbox Code Playgroud)

仅供参考,@GET工作正常.

我正在使用以下URI:

http://localhost:8080/message/jersey/sendvalue/hi
Run Code Online (Sandbox Code Playgroud)

dim*_*niy 6

GET当您在地址栏中键入任何内容时,浏览器仅发送请求.您可以在此处了解HTTP方法之间的区别:http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods

您应该使用适当的REST客户端来创建PUT请求.我正在使用的那个非常好的是Chrome的Postman扩展:链接

上述错误的原因是您正在尝试向GET/ sendvalue 发送请求,并且此方法/路径对没有映射.