瀏覽器原生彈出模態對話框,輸入帳號密碼後才能存取頁面,無需自寫登入頁。
HTTP Basic Access Authentication (RFC 7617):
伺服器回應 401 Unauthorized + WWW-Authenticate: Basic realm="Protected Area",瀏覽器自動彈窗,後續請求自動攜帶 Authorization: Basic base64(user:pass)。
Authorization 標頭,解碼驗證,失敗回 401 + 標頭。http.httpBasic()。web.xml 定義 <login-config><auth-method>BASIC</auth-method></login-config> + <security-constraint> + tomcat-users.xml 設定用戶角色。Basic Auth 僅 Base64 編碼,**必須配合 HTTPS** 否則帳密等同明文傳輸。生產環境建議改用 Form Login + JWT/OAuth2。