如何知道当前Servlet请求是否是重定向的结果?
有没有办法知道请求是否已在 Servlet 的 doGet 方法中重定向或转发?
在我的应用程序中,当用户(其会话已超时)单击文件下载链接时,他们会看到登录页面,这很好。当他们登录时,他们会立即收到他们请求的文件,而不会更新他们看到的页面,这很糟糕。基本上,他们会卡在登录屏幕上(需要刷新)。
我想要做的是,当由于重定向而请求文件时,中断此操作并简单地重定向到带有链接的页面。
也许有更好的方法来解决这个问题?
Is there a way to know if the request has been redirected or forwarded in the doGet
method of a Servlet?
In my application, when a user (whose session has timed out) clicks on a file download link, they're shown the login page, which is good. When they login, they are immediately sent the file they requested, without updating the page they see, which is bad. Basically, they get stuck on the login screen (a refresh is required).
What I want to do is interrupt this and simply redirect to the page with the link, when a file is requested as a result of a redirect.
Perhaps there are better ways to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重定向发生在客户端。浏览器根据前一个请求发送新请求,因此对于服务器来说没有什么区别。
Referer
标头可能包含一些有用的信息,但不确定。重定向时,您可以附加一些参数,例如
?targetPage=dowloadpage
,然后检查该参数是否存在。如果您希望它通过多个页面传输,您可能必须将其放在登录页面上的隐藏
字段中。The redirect happens client-side. The browser is instructed by the previous request to send a new request, so to the server it does not make a difference. The
Referer
header might contain some useful information, but it's not certain.When redirecting you can append some parameter, like
?targetPage=dowloadpage
and then check if the parameter exists. You may have to put this in ahidden
field on the login page if you want it to be transferred through multiple pages.如果您使用容器管理的身份验证,那么我不相信您可以检测到这一点,因为服务器只会在身份验证成功完成后才会涉及您的资源。
如果您以不同方式管理身份验证,请解释。
If you're using container managed authentication, then I don't believe you can detect this since the server will only involve your resource once authentication has been completed successfully.
If you're managing authentication differently, please explain.