Reputation: 672
I have a unique problem in GAE. Please note the problem I am describing below is only when I deploy code to GAE but is working fine locally... Please help guys....
I have a servlet code that sets a List object in session attribute and forwards the request to a JSP as follows:
HttpSession session=request.getSession();
session.setAttribute("msgListS", msgList);
request.getRequestDispatcher("/WEB-INF/jsp/downloadpdf.jsp").forward(request, response);
In the jsp....i am fetching the List and printing its size and then on click of a link I call another servlet. JSP code is as follows :
List<Message> msgList=(List<Message>)session.getAttribute("msgListS");
out.println("The total messages are : "+msgList.size());
session.setAttribute("msgListS", msgList);
Now in the last servlet I am fetching the List object again but here the size is coming different as the actual size of the list. In the jsp it was displaying correct but here in this servlet it showing size as 1. Please help....servlet code:
HttpSession session=request.getSession(false);
List<Message> msgList=(List<Message>)session.getAttribute("msgListS");
out.println("The total messages are : "+msgList.size());
On local machine it is working absolutely fine but GAE has above problem :(
Upvotes: 0
Views: 1273
Reputation: 3639
Are you sure you are getting the session correctly? My understanding is that you should obtain it like this:
this.getThreadLocalRequest().getSession();
That is what I do and what is recommended Google AppEngine Session Example
There is more discussion here too
When and how should I use a ThreadLocal variable?
which shows a potential downside (memory leaks)... not sure it applies though I mention it just for reference sake.
Upvotes: 1