0

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 :(
Gaurav Sachdeva
  • 652
  • 1
  • 10
  • 23
  • I know this is not the problem but are you storing `List` or `List`? Seems a bit chaotic with the generics... – Francisco Spaeth Jul 27 '12 at 19:19
  • why are you setting the value to the session again in step 2? – Francisco Spaeth Jul 27 '12 at 19:21
  • List is basically a list of Message objects. i have defined a class Message and storing its objects in the List. – Gaurav Sachdeva Jul 27 '12 at 19:23
  • in step 2 you do: `List msgList=(List)session.getAttribute("msgListS");session.setAttribute("msgListS", msgList);`, in step 3: `(List)session.getAttribute("msgListS");` wouldn't it be `String`? Or are you overriding it somewhere else? – Francisco Spaeth Jul 27 '12 at 19:25
  • sry....mybad...i just corrected the typo. – Gaurav Sachdeva Jul 27 '12 at 19:28
  • so, when you print the entire list, which instance is not showing up in the last step? is there a patter? to check it just print out the elements on your jsps – Francisco Spaeth Jul 27 '12 at 19:44
  • the pattern is like....if list has upto 4 elements,,,it will show up fine.....if list has more than 4 elements it will show the previous value....Like if list had 3 elements then it showed 3..but next time if list has 6 elements thaen also it showed 3 – Gaurav Sachdeva Jul 27 '12 at 20:12
  • Actually I am new to web development and GAE....I am using just the above code I described for session management.... – Gaurav Sachdeva Jul 27 '12 at 20:22

1 Answers1

1

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.

Community
  • 1
  • 1
user1258245
  • 3,639
  • 2
  • 18
  • 23
  • @user1258245........it is working fine when list has 4 or less objects....so i guess sessions should be fine if it working for that.......but as the objects increases more than 4, then the list size is not shown correctly and the previous value is shown. :( – Gaurav Sachdeva Jul 28 '12 at 08:01