HTTP状态405 - 请求'POST'方法不允许

时间:2015-01-19 11:27:22

标签: java spring jersey-2.0

问题是当我尝试用@POST表示法调用api时,我有这个错误:

HTTP Status 405 - Request  'POST' Method Not Allowed

其他API(@GET)有效。

web.xml是:

<servlet>
        <servlet-name>uJerseyServlet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.fasterxml.jackson.jaxrs;com.info.smarti.api</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>

    </servlet>
   <!-- 
    <servlet-mapping>
        <servlet-name>uJerseyServlet</servlet-name>
        <url-pattern>/app/*</url-pattern>
    </servlet-mapping> -->


      <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
        <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping> 

      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/application-security.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/UsersDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

更新:我尝试使用以下命令配置Tomcat:

 <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value>
        </init-param>

但仍然没有工作..所以问题可能是泽西配置..

示例API(POST):

 @Path("/cPass")
    @POST
    @ManagedAsync
    @Consumes(MediaType.TEXT_PLAIN)
    @Produces(MediaType.APPLICATION_JSON)
    public void cPassw(@QueryParam("token") String token,
            @QueryParam("categ") String category,
            @QueryParam("newpass") String newPassword,
            @Suspended final AsyncResponse response) throws Exception {
                       ....
       }

2 个答案:

答案 0 :(得分:0)

如果您使用的是Tomcat,则必须在server.xml文件中启用PUT方法

查看http://www.codereye.com/2010/12/configure-tomcat-to-accept-http-put.html

答案 1 :(得分:0)

也许您可以检查以.java结尾的文件,并且必须删除一些句子,例如“ super.doGet(request,response);”或“ super.doPost(request,response);”。在您的方法中