我需要在Tomcat上允许PUT请求,通过XAMPP安装。我在网上找到了各种答案,但没有人适合我。 我试图在我的项目web.xml中添加这段代码:
<security-constraint>
<web-resource-collection>
<web-resource-name>allow</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<!-- no auth-constraint tag here -->
我还尝试修改服务器Tomcat web.xml:
<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>
但每个PUT仍然无法正常工作。在Postman上测试,响应状态为204,但该方法未执行。 你能帮助我吗?
答案 0 :(得分:0)
<security-constraint>
<web-resource-collection>
<web-resource-name>allow</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<!-- no auth-constraint tag here -->
这些限制或“约束”可以执行的方法。只在这里添加你不想允许的内容。