使用了360网站安全检测 查到有OPTIONS方法
百度了下 https://my.oschina.net/maliang0130/blog/338725
找到这个方法奈何http.conf 找不到无论在tomcat目录里还是linux路径下的/usr/etc或者apache2
最后通过开源中国找到
第一步:修改应用程序的web.xml文件的协议
xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
第二步:在应用程序的web.xml中添加如下的代码即可
<security-constraint> <web-resource-collection> <url-pattern>/*url-pattern> <http-method>PUThttp-method> <http-method>DELETEhttp-method> <http-method>HEADhttp-method> <http-method>OPTIONShttp-method> <http-method>TRACEhttp-method> web-resource-collection> <auth-constraint> auth-constraint> security-constraint> <login-config> <auth-method>BASICauth-method> login-config>
重新部署程序,重启tomcat即可完成
如果用户要验证既可以将POST和GET也添加在其中,重新部署并启动tomcat即可看到效果
以上的代码添加到某一个应用中,也可以添加到tomcat的web.xml中,区别是添加到某一个应用只对某一个应用有效如果添加到tomcat的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
>
web-resource-collection
>
<
auth-constraint
>
auth-constraint
>
security-constraint
>
<
login-config
>
<
auth-method
>BASIC
auth-method
>
login-config
>