Skip to content
Advertisement

How to deal with Sessions in Google App Engine?

I am successfully creating sessions in servlet and I can get sessions/ session attribute to jsp but not in endpoints class. I want to get the sessions info in endpoints classes. Please help me with this.

I am using maven in eclipse and I enabled sessions in appengine-web.xml

I read an article about this also except how to enable session I din’t understand anything.

This servlet is to check whether there is an already a session

JavaScript

If session is not there create session using this servlet

JavaScript

This is my endpoints api class (Google Cloud Endpoints)

JavaScript

I am still getting “no Name” as result even though I created session and i can get the session attribute, here “name”

Advertisement

Answer

Assuming you know about HttpSessions (if not it’s simply cookie exchanged between sever and client in order to deal with the logged-in user).

So all user related or any other session-related information is stored in the server end and a session ID representing the information will be sent as cookie to the client, and the client will sent it back on every HTTP request.

AppEngine uses Datastore to store the session information and memcache for faster access to that information.

You can access the session data using a standard HttpSession object injected in every HTTP request.

The code to access this HttpSession varies in frameworks you use. If you want, I can specify code snippets to help to understand.

UPDATE:

If you are using servlets, then accessing session information will look like the following:

JavaScript

And for Google Cloud endpoints, use the following:

JavaScript
Advertisement