简体   繁体   English

在地址栏中输入网址时重定向到登录页面

[英]To redirect to login page when url is entered in address bar

I have html pages in my java web application,with business logic handled in servlets. 我的Java Web应用程序中有html页面,业务逻辑在servlet中处理。 If the url of any page is directly entered in the browser address bar i need to redirect to the login page.Can someone help me on how i can achieve this feature. 如果直接在浏览器地址栏中输入任何页面的网址,则需要重定向到登录页面。有人可以帮助我实现此功能。

Thanks in advance. 提前致谢。

You can use security framework which automatically redirects you to login page once unauthenticated. 您可以使用安全框架,该框架在未经身份验证后会自动将您重定向到登录页面。 It is more complicated but it is should be more reliable in long run. 它更复杂,但从长远来看应该更可靠。 Check this out: Apache Shiro. 检查一下:Apache Shiro。

When user loading page, servlet calls DAO to load data from database. 当用户加载页面时,servlet调用DAO从数据库加载数据。 You can check session/cookies/request in servlet, if this user have token to access the data and sendRedirect to login page if not. 如果该用户具有访问数据的令牌,则可以检查servlet中的会话/ cookie /请求,如果没有令牌,则可以将其发送到登录页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM