java GWT 会话管理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4453611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:27:23 来源:igfitidea点击:
GWT session management
提问by Noor
I don't too much about gwt session on java. I've some doubts about it. Anyone can check if the implementation below is the way it needs to be done.
我不太了解 java 上的 gwt 会话。我对此有些怀疑。任何人都可以检查下面的实现是否是它需要完成的方式。
public class ServiceImpl extends RemoteServiceServlet implements Service
{
void CreateSession(String Username)
{
HttpServletRequest request = this.getThreadLocalRequest();
HttpSession session = request.getSession();
session.setAttribute("Username", Username);
}
boolean ValidateSession(String Username)
{
HttpServletRequest request = this.getThreadLocalRequest();
HttpSession session = request.getSession();
if (session.getAttribute("Username"))
{
return true;
}
return false;
}
}
Is this the correct way to implement these two function???
这是实现这两个功能的正确方法吗???
回答by
a few correction
一些更正
void createSession(String Username) {
getThreadLocalRequest().getSession().setAttribute("Username", Username);
}
boolean validateSession(String Username) {
if (getThreadLocalRequest().getSession().getAttribute("Username") != null) {
return true;
} else {
return false;
}
}
回答by Isaac Truett
This LoginSecurityFAQis a good place to start.
这个LoginSecurityFAQ是一个很好的起点。