Reputation:
I have a hard time with Google AppEngine and sessions.
I have a Java GAE application that works smoothly on my localhost, but as soon as I deploy it on GAE the session variable's collection is null.
The workflow is following: I have data stored in a class within the session, then read it is a JSP page. Send the response to the servlet, modify it there, store it and show another JSP.
I have checked it: the data (a collection) is still in the variable in the servlet, but when it comes to the JSP, the collection is null.
Have you got any ideas why is it acting so strangely?
Thanks.
Upvotes: 0
Views: 370
Reputation: 205
You have to do two things to enable session:
1 In war/WEB-INF/appengine-web.xml
<sessions-enabled>true</sessions-enabled>
2 All objects you store in session should implements java.lang.Serializable
public class ParameterForSession implements Serializable {
// Your code here
}
Upvotes: 1
Reputation: 2520
Can you post the data model you are putting into the session collection? Some objects which, despite being java serializable, are not memcache/session serializable; gxt models for instance, come to mind. Objects which are enhanced, or which ultimately rely on a transient map cannot be saved to session or memcache. Try saving just the objects themselves, and then check your results, or for stacktraces which will directly tell you if there is a serialization problem.
If you cannot serialize your model as-is, consider using an ObjectOutputStream to convert your objects to serializable byte[], or use another serialization mechanism like GWT RPC serializer to convert to a string.
Upvotes: 0
Reputation: 2701
Make sure all objects stored in the session implement the java.io.Serializable
interface.
Upvotes: 0
Reputation: 4474
Did you enable sessions in your appengine-web.xml file ?
Look at
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
Upvotes: 2