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 Adding a parameter to a request 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 "Adding a parameter to a request" Watch "Adding a parameter to a request" New topic

Adding a parameter to a request

David Swan
Ranch Hand

Joined: Oct 08, 2003
Posts: 33
Firstly let me appologise for the amount of questions im asking......
Can anyone tell me how to add a parameter to a HttpServletRequest. Say for example if i wanted to add a parameter to it and then dispatch it off by forwarding it to another servlet. Do i use something like setAttribute???
What exactly does an attribute mean, is an attribute the same as a parameter etc as they are both stored in the body when using POST???

Andy Smith
Ranch Hand

Joined: Sep 28, 2003
Posts: 239
Yes David u r absolutely correct..
U can very well use setAttribute ro store the paramter...

And this is same like the attribute in <html>.

Share Knowledge to gain it.
SCJP 2, SCWCD 2, SCDJWS, IBM 141 (In Progress), IBM 486 (Next)
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Attributes are Objects, parameters are Strings.
"The journey is the reward."

kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
carl chan
Ranch Hand

Joined: Mar 12, 2003
Posts: 42
hi david,
other than adding some attributes to your request object, i suggest that you also try to add some attributes to your HttpSession becasue using session to store the "shared object" between jsp and servlet is an important method too.
Have fun, hope this help.
David Swan
Ranch Hand

Joined: Oct 08, 2003
Posts: 33
Cheers everybody thanks for the help...
michael brosnahan

Joined: Mar 18, 2002
Posts: 9
HttpServletRequest parameters can not be set. They can only be got.
The only thing that can be set on a request is attributes
Sathya Sankar
Ranch Hand

Joined: Sep 16, 2000
Posts: 67
HttpServletRequest parameters can not be set. They can only be got.

That statement is not entirely true. You are partially right because we cannot set request parameters within a jsp/servlet with a call like request.setParameter(name, value). However, when we include/forward a page in JSP we can set addtional request parameters. For eg:

Now test1.jsp can retrieve this parameter with request.getParameter("temp"). The container is responsible for passing these run time parameters to the included/forwarded page. It usually appends them as query string to the URL and includes/forwards to the specified page.

I agree. Here's the link:
subject: Adding a parameter to a request
It's not a secret anymore!