I am having the same problem. Object on my local GAE install can't be
stored in the session. Very detrimental for user session management.

Here is the line in my appengine-web.xml:
<sessions-enabled>true</sessions-enabled>

I store my user in session from inside a Filter:

 HttpSession session = httpRequest.getSession();
 session.setAttribute(WebConstants.USER_KEY, user);

When I try to retrieve the user in my JSP, I get a null for

<% User user = (User) session.getAttribute(WebConstants.USER_KEY); %>

How is this possible such basic JSP handling could be failing?
Could you please explain?

Thanks.

On Nov 11, 11:51 am, "Ikai L (Google)" <ika...@google.com> wrote:
> Ilya,
>
> One thing you will want to check will be if sessions are enabled. Sessions
> are off by default, so you'll have to add this line to your
> appengine-web.xml file:
>
>     <sessions-enabled>true</sessions-enabled>
>
> http://code.google.com/appengine/docs/java/config/appconfig.html#Enab...
>
>
>
>
>
> On Tue, Nov 10, 2009 at 12:03 PM, IlyaE <ilyaelk...@gmail.com> wrote:
>
> > I'm looking to track a user session if they have "logged in" using my
> > own user manager, but i was having trouble passing my user object back
> > to the session once the app was deployed. I will give this a shot but
> > i wonder if this was because i was redirecting instead of forwarding.
>
> > I was doing this in my servlet
> >                List<MyUser> results = (List<MyUser>)
> > query.execute(email,password);
>
> >                if (results.size() == 0) { redirect = "/index.html"; }
> >                else {
> >                        req.getSession().setAttribute("user",
> > results.get(0));
> >                }
>
> >                resp.sendRedirect(redirect);
>
> > and this in my jsp
> > <%
> > MyUser u = (MyUser) request.getSession().getAttribute("user");
> > if (u != null) {
> >        ....
> > } else { %>
> > User is null
> > <% } %>
>
> > So i was always getting null even though i was redirected properly.
>
> > Can you explain
>
> > On Nov 10, 1:36 pm, "Ikai L (Google)" <ika...@google.com> wrote:
> > > Ilya,
>
> > > Are you looking to persist objects for a lifetime of a session, or are
> > you
> > > looking to minimize the logic you are using in your JSPs?
> > > As a general design principle, we recommend that you minimize usage of
> > > session scope. Variables bound to session scope are serialized and stored
> > to
> > > distributed memory, and as a result, it will work best if you use it to
> > pass
> > > around small, simple, immutable objects.
>
> > > If you're looking to pass a variable to a view, Java Servlets have a
> > concept
> > > of page scope as well as session scope. You don't need to store a
> > variable
> > > in session scope if you just want to dispatch the request to a JSP. For
> > > instance, you can define a Servlet that looks like this:
>
> > > public class MyServlet extends HttpServlet {
>
> > >    protected void doGet(HttpServletRequest request, HttpServletResponse
> > > response) throws ServletException, IOException {
> > >      String myVar = "this is a string that will be passed to the JSP";
> > >      request.setAttribute("myVar", myVar);
> > >      RequestDispatcher dispatcher =
> > > request.getRequestDispatcher("/WEB-INF/my.jsp");
>
> > >      dispatcher.forward(request, response);
>
> > >    }
>
> > > }
>
> > > In my.jsp, you can now refer to this variable:
>
> > > <%@ page isELIgnored="false" %>
> > > <body>
> > >   <h1>${myVar}</h1>
> > > </body>
>
> > > Ikai Lan
> > > Developer Programs Engineer, Google App Engine
>
> > > On Tue, Nov 10, 2009 at 2:39 PM, IlyaE <ilyaelk...@gmail.com> wrote:
>
> > > > Well as i found out, session attributes don't always guarantee that
> > > > they are sent back to the same JVM thus i keep getting null objects in
> > > > my view. While i saw a similar discussion before the only examples i
> > > > found were for Python. I'm looking for a simple java example that
> > > > saves an object in the servlet and retrieves it in the jsp.
>
> > > > On Nov 9, 5:44 pm, victor <victoraco...@gmail.com> wrote:
> > > > > What issue are you encountering?
>
> > > > > When you make changes to a session object state, make sure to
> > > > > explicitly call the session.setAttribute("<you session ID>", <you
> > > > > modified session state object>) again.
>
> > > > > i think there is an issue discussed about this before.
>
> > > > > On Nov 9, 10:58 am, IlyaE <ilyaelk...@gmail.com> wrote:
>
> > > > > > Does anyone have a java session handleing example? It seems that
> > > > > > saving objects in the session only works locally.
>
> --
> Ikai Lan
> Developer Programs Engineer, Google App Engine

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=.


Reply via email to