使用了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>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>
?重新部署程序,重啟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
>