Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher.forward attributes

 
Ian Perkins
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The Web Services Tutorial (1.4) says that:
p665...
"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...
Thanks
Ian
 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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>").
 
Ian Perkins
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shankar,
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.
Regards
Ian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic