查看tomcat日志,發現有些請求方式是CONNECT、HEAD,不是正常的請求,決定禁掉這樣的。在web.xml上加上下面代碼可以禁掉這些請求方式,以這些方式請求服務tomcat將會返回403狀態。
(加在tomcat/conf/web.xml下會對整個tomcat生效,加在單個項目下只會對這個項目生效)
<security-constraint> <web-resource-collection> <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> <http-method>CONNECT</http-method> </web-resource-collection> <auth-constraint></auth-constraint> </security-constraint>