java会话跟踪
可能的重复:
Java页面重定向
我想在第一次调用某个页面时转到该页面并在会话仍处于活动状态时始终转到另一个页面。我已经有了一个登录机制。我做了另一个主题,并建议在会话层设置一个标志。我不知道如何实现这个。
基本上,如果当他们按下按钮转到某个页面时,它会这样调用:
public int show(Action action) throws Exception {
HttpServletRequest request = action.getRequest();
action.setJspURI("objects/objects_guidlines.jsp");
return FORWARD;
}
如果他们是第一次来这里,那就没问题。我如何实施检查以查看这是否是第一次,然后发送到另一个页面?
Possible Duplicate:
Java page re-direct
I want to go to a certain page the first time it calls that page and go to another page all times after that while the session is is still active. I already have a login mechanism in place. I made another topic and was suggested to set a flag on the session layer. I'm not sure how to implement this.
Basically if when they press a button to go to a page it calls this:
public int show(Action action) throws Exception {
HttpServletRequest request = action.getRequest();
action.setJspURI("objects/objects_guidlines.jsp");
return FORWARD;
}
This is fine if they are coming here for the first time. How can I implement a check to see if this the first time or not and subsequently send to another page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTTP 是一种无状态协议,因此如果您想在请求之间维护状态(例如用户之前是否来过这里),您需要使用 cookie 或会话之类的东西。
如果要使用会话,可以从 HttpServletRequest 获取它并执行以下操作:
HTTP is a stateless protocol so if you want to maintain state between requests (such as whether the user has been here before), you'll need to use something like cookies or sessions.
If you want to use the session, you can get it from the HttpServletRequest and do the following:
您需要一个静态变量或单例类来检查这一点。
在 servlet 中,您可以声明一个静态变量来强制执行此检查,如果您无权访问该变量,则可以使用单例。
答案还取决于您的架构。
You would need a static variable or a singleton class to check this.
In servlets you can declare a static variable to enforce this check, if you do not have access to that then you can use a singleton.
Answer also depends upon your architecture.