Ikai
Even this basic page scope isn't working for me.
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
req.setAttribute("helloWorld", "Testing");
RequestDispatcher dispatcher =
req.getRequestDispatcher("/helloworld.jsp");
dispatcher.forward(req, resp);
}
<%@ page isELIgnored="false" %>
<body>
Hello world
<% String str = (String) session.getAttribute("helloWorld"); %>
<h1>${helloWorld}</h1>
</body>
The value for ${helloWorld} is null.
I am testing this through eclipse.
Google App Engine Java SDK 1.2.6
Google Web Toolkit SDK 1.7.1
Google Plugin for Eclipse 3.5
I am running this on mac (snow leopard).
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode)
On Nov 10, 10:36 am, "Ikai L (Google)" <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=.