Variables in pageContext scope are only available to the JSP. It looks like you should be setting variables in the request scope.

-Tim

Michael Neel wrote:

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]

Reply via email to