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. --~--~---------~--~----~------------~-------~--~----~ 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-java@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=en -~----------~----~----~----~------~----~------~--~---