File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes RequestDispatcher.forward attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "RequestDispatcher.forward attributes" Watch "RequestDispatcher.forward attributes" New topic

RequestDispatcher.forward attributes

Ian Perkins

Joined: Dec 18, 2003
Posts: 19
The Web Services Tutorial (1.4) says that:
"When a request is forwarded, the request URI is set to the path of the forwarded page. The original URI and its constituent parts are saved as request attributes javax.servlet.forward.[request_uri|context-path|servlet_path|path_info|query_string]."
The first sentence is true but I cannot find the attributes mentioned in the second sentence anywhere in the request which arrives in the forwarded resource (in my case, it is a servlet).
Please can someone explain where these attributes can be found? Also, if they are there somewhere, then do the names mentioned in the tutorial represent String vales for the names used to retrieve the attributes?
I am using Tomcat 4.1.24 on Windows XP in case it is relevent...
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
When u forward the request to the another page using the forward method, u can access all the request parameters on the new page. As far as the statement is saying, it might be internally transmitting it as attributes but still u can access ur request parameters with request.getParameter method or if u have set any attributes urself, u can access them by request.getAttribute("<attribute name>").

"Failure is not when you fall down; its only when you fail to get up again."
Ian Perkins

Joined: Dec 18, 2003
Posts: 19
Thanks for your reply but perhaps I did not fully explain my question...
If I 'include' another servlet and then look in the request passed into the 'included' servlet doXXX method then I do indeed see some attributes which the server has created - in other words I don't have to do anything except retrieve these attributes using the names given in the tutorial.
However, if I 'forward' to a servlet, there are no added attributes in the request when it arrives in the 'forwarded' resource.
This seems to be at odds with what the tutorial suggests - in fact there is also an objective in SCWCD 1.4 which mentions these attributes but I don't know why the forwarding mechanism is not establishing them.
I agree. Here's the link:
subject: RequestDispatcher.forward attributes
It's not a secret anymore!