頁面 A 生成驗證碼圖片並存入 session.setAttribute("code", "1234")。頁面 B 以 <img src="A.jsp"> 載入圖片,同時讀取 session.getAttribute("code") 顯示為 null;重新整理後才正確。
<img> 發起**獨立請求**,若 Session ID 透過 Cookie 傳遞,首次請求可能尚未建立 Session(或 Cookie 未送達)。<img src="CaptchaServlet">。$.get("/checkSession") 直到 Session 有值再顯示圖片。<input type="hidden" name="captcha" value="${sessionScope.code}"> 傳回,前端提交時攜帶。