tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: Tomcat 4.0 Beta3 and Request Attributes Error
Date Wed, 02 May 2001 22:47:39 GMT


On Wed, 2 May 2001, Charles Chen wrote:

> RequestDispatcher.forward() returns immediately BUT the JSP page has not
> been processed yet!

That isn't actually true -- by the time that the forward() call returns,
the forwarded-to servlet will indeed have been executed.  Whether the
output has been committed back to the user or not is up to the included
servlet or page.

> The JSP page will only be processed after the servlet
> finishes the work, i.e., your doGet or doPost returns. Therefore, there is
> no way to access attributes in the JSP page inside the calling servlet.
> 

Also not true, particularly for the case Ana talked about -- which was an
include() and not a forward().  Again, by the time that the
include() returns, the called servlet or page will definitely have been
processed.

Formerly, Tomcat 4.0 was wrapping the request being passed on to the
included servlet (so that it could add the special request attributes
visible to included servlets), and throwing the wrapper away when the
include() returned.  I just checked in a patch so that any calls to
request.removeAttribute() or request.setAttribute() will be passed on up
to the real request, so that the changes are still visible in the calling
servlet.  This fix will show up in tonight's nightly build.

> 
> 
> Cheers,
> 
> 
> 
> Charles Chen
> 

Craig McClanahan


> 
> -----Original Message-----
> From: Ana [mailto:anbarpuc@yahoo.es]
> Sent: 02 May 2001 17:23
> To: :
> Subject: Tomcat 4.0 Beta3 and Request Attributes Error
> 
> 
> Hi,
> We think we have discovered an error. We call the include method of the
> RequestDispatcher from a servlet. Then,  we  call the setAttribute method
> of the request object  of the included JSP. If we call the getAttribute
> method of the request object in the servlet (after the include call), then
> there is not attribute.
> 
> Example:
> 
> MyServlet.java:
> 
> ...
> public void service(ServletRequest request, ServletResponse response){
>     ...
> 
> getServletConfig().getServletContext().getRequestDispatcher("MyJSP.jsp").for
> ward(request,
> response);
>     Object obj = request.getAttribute("MyAttribute");
>     // obj is null !!!!!!!!!!!!!!!!!!!!!!!!!!!!
>     ...
> }
> 
> MyJSP.jsp:
> 
>     ...
>     request.setAttribute("MyAttribute", obj);
>     ...
> 
> Thank you.
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> 


Mime
View raw message