【发布时间】:2014-09-23 14:11:45
【问题描述】:
我正在使用 web.xml 来尝试禁用我们不使用的 HTTP 方法并返回一个不包含任何 tomcat 信息的正文。
所以我已将应用的 web.xml 更改为:
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>TRACE</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>DELETE</http-method>
<http-method>HEAD</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
因此,被阻止的方法返回 403 并带有一个空主体,表示禁止。但是 TRACE 会返回一个带有 Tomcat HTML 页面的 405。
我尝试通过 ErrorServlet 重定向所有错误:
<error-page>
<location>/ErrorServlet</location>
</error-page>
这只是确保内容主体为 0。但这似乎并没有拦截这些。
那么,为什么 TRACE 会受到不同的对待?
谢谢
【问题讨论】:
标签: java tomcat tomcat7 web.xml