这个问题之前问过How to make Apache Tomcat accept DELETE method ,但它提供的解决方案对我不起作用。我已经添加了
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
到 web.xml 和我的 <servlet>
设置如下所示:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
但是,访问 DELETE
时我仍然得到 405 .有什么建议吗?顺便说一句,我已经重新启动了 tomcat。
最佳答案
查看源代码: Default Servlet
如果网络资源的删除调用失败,您可以看到返回状态代码 405 Not allowed。
从您的问题中不清楚您要删除什么 - 似乎无法删除您的资源。
On each HTTP DELETE request processed by this servlet, the following >processing shall be performed:
- If modifications to the static resources are not allowed (set by a configuration parameter), return HTTP status 403 (forbidden).
- If an attempt is made to delete a resource from /META-INF or /WEB-INF, return HTTP status 403 (forbidden).
- If the requested resource does not exist, return HTTP status 404 (not found)
- Unbind the resource from the directory context containing the static resources for this web application. If successful, return HTTP status 204 (no content). Otherwise, return HTTP status 405 (method not allowed).
无论是源代码还是功能规范,您都可以看到删除方法已被 Servlet 接受,您只需将 URL 传递给实际可删除的资源即可。
关于Tomcat,启用DELETE方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30700769/