转发请求时的 Servlet/JSP URL
我的 Web 应用程序有一个名为 admin 的 servlet,在导航时检查用户是否登录以及是否定向到管理部分,但如果没有,它会将用户定向到带有登录表单的 JSP 页面。 JSP 的名称不会出现在 URL 中,它仍为 /admin。 但是,当 JSP 发布到另一个 servlet 来验证登录凭据时,url 会更改为 /validate,这是 servlet 的名称。 如果用户验证,他们将被转发到另一个 JSP,但 URL 仍保留为 /validate。 如何确保 URL 反映浏览器中正在查看的内容?
如果这不太清楚,请道歉。
My web app has a servlet called admin which when navigated to checks if the user is logged in and if the are directs to the the admin section, but if they aren't it directs them to a JSP page with a sign-in form. The name of the JSP doesn't appear in the URL, it stays as /admin. But then when the JSP posts to another servlet to validate the sign-in credentials the url changes to /validate which is the name of the servlet. If the user validates they are forwarded to another JSP, but the URL still remains as /validate. How can I ensure the URL reflects what is being viewed in the browser?
Apologies if this isn't too clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用重定向,而不是转发。 转发是服务器内部的; 来自浏览器的一个请求被转发到不同的 servlet。 重定向是服务器和浏览器之间的交互,告诉浏览器请求第二个 URL。
我建议使用容器管理身份验证,每当用户请求需要身份验证的页面时,它将处理重定向到表单并返回到最初请求的页面。
Use a redirect, rather than forwarding. Forwards are internal to the server; one request from the browser is forwarded to different servlets. A redirect is an interaction between the server and the browser, telling the browser to request a second URL.
I would recommend using Container Managed Authentication, which will handle the redirect to the form and back to the originally requested page for you whenever a user requests a page that requires authentication.