HTTP请求1.0支持:post get head
HTTP请求1.1的时候支持了:put delete options trace connect
可以自行禁止使用哪些请求,只需要在web.xml中添加配置信息:
<security-constraint> 不通过编程就可以限制对某个资源的访问
<web-resource-collection>
<url-pattern>/*</url-pattern> 拦截所有的url
<http-method>PUT</http-method> 禁止put请求
<http-method>DELETE</http-method> 禁止delete请求
<http-method>HEAD</http-method> 禁止head请求
<http-method>OPTIONS</http-method>禁止options请求
<http-method>TRACE</http-method> 禁止trace请求
<http-method>CONNECT</http-method>禁止connect请求
<http-method>POST</http-method> 禁止post请求(不建议)
<http-method>GET</http-method> 禁止get请求(不建议)
</web-resource-collection>
<auth-constraint></auth-constraint> 授权约束
</security-constraint>
这样就禁止了所有的请求方式。
如果<url-pattern>报错可以在:<web-app 的xmlns:xsi里添加: http://www.springmodules.org/schema/cache/springmodulescache.xsd
http://www.springmodules.org/schema/cache/springmodulesehcache.xsd
在禁止了一部分请求后,如果再次发送改请求会有相应的错误产生,如:405,403。。。。
建议添加相应的报错页面否则容易暴露自己的tomcat、版本,项目信息,太不安全。
关于post get head put delete options trace connect的相关作用请查阅官方文档