• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding a parameter to a request

 
David Swan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>.
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
Attributes are Objects, parameters are Strings.
kktec
SCJP, SCWCD, SCJD
"The journey is the reward."
 
carl chan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers everybody thanks for the help...
 
michael brosnahan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
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.
Ciao,
GSS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic