主要是在tomcat的web.xml或者项目的web.xml中配置以下参数
<security-constraint>
<web-resource-collection>
<web-resource-name>fortune</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint></auth-constraint>
</security-constraint>
2,上面参数理论上来说可以禁止PUT,DELETE,HEAD,OPTIONS,TRACEZ等方法访问tomcat,但是http的返回码不同,其中PUT,DELETE,HEAD,OPTIONS的返回码是403,表示此请求已经被服务器锁禁止,但是 TRACE返回的404,表示此请求直接不存在,并且提示 用户可以使用POST,GET, PUT,DELETE,HEAD,OPTIONS,等请求去访问,电科院测试这块默认不可以提示用户可以使用PUT,DELETE,HEAD,OPTIONS去进行请求,
3,修改方法单独 TRACE请求为什么会未禁止,并提示上面信息,主要是因为 TRACE请求在tomcat中已经默认完全禁止,既此请求已不存在 ,所以才会返回 404 ,而不是403 ,想通过电科院测试可以直接修改 tomcat的默认配置 ,既先将tomcat中 的 TRACE 请求开启,,在通过上面 1 的配置参数就会 统一返回 403了
4,tomca开启 TRACE方法如下
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="utf-8"
redirectPort="8443"
allowTrace="true"
/>
allowTrace="true" 代表开启 TRACE方法