简体   繁体   English

在Google App Engine的会话中维护列表对象

[英]Maintaining List Object in Session on Google App Engine

I have a unique problem in GAE. 我在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.... 请注意,我在下面描述的问题仅是在我将代码部署到GAE时,但是在本地运行良好。

I have a servlet code that sets a List object in session attribute and forwards the request to a JSP as follows: 我有一个servlet代码,该代码在session属性中设置一个List对象,并将请求转发到JSP,如下所示:

        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中。...我正在获取列表并打印其大小,然后单击链接,然后调用另一个servlet。 JSP code is as follows : JSP代码如下:

        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. 现在,在最后一个servlet中,我再次获取List对象,但是这里的大小与列表的实际大小有所不同。 In the jsp it was displaying correct but here in this servlet it showing size as 1. Please help....servlet code: 在jsp中,它显示正确,但是在此servlet中,它的大小显示为1。请帮助...。servlet代码:

       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 :(

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 那就是我的工作,推荐的Google AppEngine会话示例

There is more discussion here too 这里也有更多讨论

When and how should I use a ThreadLocal variable? 什么时候以及如何使用ThreadLocal变量?

which shows a potential downside (memory leaks)... not sure it applies though I mention it just for reference sake. 这表明存在潜在的负面影响(内存泄漏)...尽管我仅出于参考目的而提及它,但不确定它是否适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM