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
-~----------~----~----~----~------~----~------~--~---

Reply via email to