我需要在我的Application Server,Apache Tomcat 6.0上禁用PUT,DELETE和TRACE HTTP请求。
所有其他来源,我已经搜索到现在,已经指示我走向httpd.conf中的limit参数,因此我事先说明我没有使用Apache Web Server,并且请求直接由Tomcat处理,并且所以图片中没有httpd.conf。
请建议我如何在Tomcat上进行操作?
在您的WEB INF中,添加您可以添加安全约束:
<security-constraint>
<web-resource-collection>
<web-resource-name>Forbidden</web-resource-name>
<url-pattern>/blah/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>empty_role</role-name>
</auth-constraint>
</security-constraint>
或者,您可以执行以下两项操作:
在server.xml中,编辑<connector>
元素,添加一个属性:allowTrace="false"
。然后编辑DefaultServlet:$ CATALINA_HOME / conf / web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<!-- blah blah blah -->
<init-param>
<param-name>readonly</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
答案在于servlet规范。在查看servlet的API:http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http/HttpServlet.html时,您会看到不同的方法处理不同类型的HTTP请求。此外,还有一个称为过滤器的强大功能,可用于围绕servlet和过滤器包装一些代码。
所以解决方案是: