GWT session management
Asked Answered
G

2

5

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.

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???

Goblet answered 15/12, 2010 at 18:41 Comment(2)
` if (session.getAttribute("Username"))` will this compile ?Mitchiner
Here are some best practices on session management hope this will help youMitchiner
S
6

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;
        }
    }
Smashup answered 15/12, 2010 at 18:50 Comment(5)
Is there anyway, I can identify a valid session with the use of any username and only the thread??Goblet
traditional java/jsp/servlet programming. write any servlet or jsp and take the session from the requestSmashup
I'm new to java, Can u show me a simple example to perform thisGoblet
@Goblet here is the simple java session tutorial. apl.jhu.edu/~hall/java/Servlet-Tutorial/…Smashup
Can I annotate this as @Stateless, so I can scale horizontally?Spurry
P
5

This LoginSecurityFAQ is a good place to start.

Position answered 15/12, 2010 at 18:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.