# [Java]HTTP Method用白名單方式設定 ###### tags: `Java` 如果想用白名單方式列出只能用GET 和 POST方法,可用以下設定在web.xml ``` <!-- ----白名单start---- --> <security-constraint> <web-resource-collection> <web-resource-name>WhiteList</web-resource-name> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> </security-constraint> <!-- 限制其他方法访问 --> <security-constraint> <web-resource-collection> <web-resource-name>RestrictedMethods</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint> <!-- ----白名单end---- --> ``` 原理是: 1. 沒有寫auth-constaint,代表:任何人可用上面的 方法 2. <auth-constraint/>代表:沒有人可以用上面的方 法 3. 然後上下兩個聯集 所以上述設定翻譯年糕: 第一段 - 任何人可用POST GET 第二段 - 沒有人可以用任何方法 聯集後 - 任何人只可用post get
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up