Thanks Tim and Steve... though a combination of session.setAttribute
and request.setAttribute I'm able to put thing where I want.

In retrospect that seems so obvious...

Mike

On 10/26/05, Steve Kirk <[EMAIL PROTECTED]> wrote:
>
> not sure about use of PageContext, never used it.
>
> ... or about the "correct" way to pass info from servlet to jsp (if there
> even is one), but if it helps, I use this approach and it works well:
>
> // in the servlet's doPost()
> request.setAttribute(MyConstants.MY_OBJECT_CONSTANT_NAME, myObject);
> request.getRequestDispatcher("blah.jsp").forward(request, response);
>
> // in the JSP
> Object myObject = request.getAttribute(MyConstants.MY_OBJECT_CONSTANT_NAME);
>
> > -----Original Message-----
> > From: Michael Neel [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday 26 October 2005 16:12
> > To: users@tomcat.apache.org
> > Subject: getPageContext returns null
> >
> >
> > Hi,
> >
> > Quick overview, I'm setting some variables in the session from my
> > servlet to be used in my JSP/JSTL page.  Everything is fine if a JSP
> > page is called before the servlet, but a call to the servlet first
> > results in JspFactory.getPageContext to return null.
> >
> > To reproduce, I restart the Tomcat server, clear the session cookies
> > from the client, and go to the servlet URL directly.
> >
> > I found this bug report which is the problem exactly:
> > http://issues.apache.org/bugzilla/show_bug.cgi?id=3752
> >
> > If i go to a jsp page after starting the server, any JSP page, then go
> > to the servlet url directly everything works as expected.  Like the
> > bug poster, if this is a no-no I'm curious why the factory and the
> > call to create the context throw no exceptions.  I'm more curious
> > though as to what the correct way is for passing information from
> > servlet to jsp.
> >
> > Mike
> >
> > A stripped down version of the code in question:
> >
> >       RequestDispatcher dispat = null;
> >
> >       JspFactory factory = JspFactory.getDefaultFactory();
> >       PageContext pageContext = this.factory.getPageContext(
> > this, request, response,
> >                       null, false, JspWriter.DEFAULT_BUFFER, true);
> >
> >       // expected URL is something like /AppName/SevrletName/45
> >       // path_info is '/45'
> >       String id = request.getPathInfo().substring(1);
> >
> >       // *snipping* sql-setup to look up 'id'
> >       ResultSet rs = sql.executeQuery();
> >       if(rs != null) {
> >               rs.next();
> >               String title = rs.getString("title");
> >               String preamble = rs.getString("preamble");
> >
> >               pc.setAttribute("title", title,
> > PageContext.REQUEST_SCOPE);
> >               pc.setAttribute("preamble", preamble,
> > PageContext.REQUEST_SCOPE);
> >
> >               dispat =
> > getServletContext().getRequestDispatcher('page1.jsp');
> >       }
> >       else {
> >               pc.setAttribute("errorMessage", "ID was not found",
> > PageContext.REQUEST_SCOPE);
> >               dispat =
> > getServletContext().getRequestDispatcher('error.jsp');
> >       }
> >
> >       factory.releasePageContext(ps);
> >
> >       dispat.forward(request, response);
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to