我使用一个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。但这似乎并不能截取这些。
那么为什么跟踪会被不同的对待呢?
谢谢
发布于 2014-07-31 15:11:00
这对我来说是非常有意义的,因为在所有情况下,除了跟踪之外,您都提交了由URL和代码403标识的web资源请求,这意味着对资源的访问被拒绝。尝试使用允许的方法访问相同的资源。可能对他们也是禁止的吧?
另一方面,跟踪不需要访问任何资源,它只是回显客户端的输入,所以405 (“不允许的方法”)看起来适合这种情况。
有自定义错误页面是个好主意。具体针对每个错误代码的示例可以在这里找到:https://serverfault.com/questions/254102/custom-error-pages-on-apache-tomcat
https://stackoverflow.com/questions/25062176
复制相似问题