首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Java Web 專案訪問根路徑自動跳轉到登錄頁的配置原理

     編輯:程式設計綜合問答

默認歡迎文件機制

當請求路徑為目錄(以 / 結尾)時,Servlet 容器按 web.xml 中 <welcome-file-list> 順序查找文件:

<welcome-file-list>
  <welcome-file>login.jsp</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>index.html</welcome-file>
</welcome-file-list>

跳轉到 login.action 的常見配置

  1. welcome-file 指向 login.jsp,jsp 內部 <c:redirect url="/login.action"/> 或 response.sendRedirect。
  2. Filter 攔截根路徑,未登錄用戶重定向到登錄頁。
  3. Spring MVC 配置:@RequestMapping("/") 方法返回 redirect:/login。

排查步驟

  1. 查看 web.xml 的 welcome-file-list。
  2. 檢查是否有 Filter 映射 /* 或 /。
  3. 搜索代碼中 sendRedirect、forward 到 login.action 的位置。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved