Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Manuplate the HttpServletRequest...

 
Bala Krishniah
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to add one more parameter to the request object.
Unfortunately, there is no HttpServletRequest.setParameter()
Is there any way?
 
Malu Sivasankar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
U have the method
setAttribute(String name,Object o) which stores an attribute in HttpServletRequest
 
Bala Krishniah
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that. It puts the value in the session, but not in the request. ie on the other send I have to use getAttribute() method. But I cant use getParameter(), the way you do when you get it in request......
So is there any other way to manuplate and append the parameter to the request directly.
Thanks
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This probably doesn't help, but version 2.3 of the Servlet API includes the concept of request and response wrappers and filters to be preocessed before and after requests. I believe this would easily solve the problem, but version 2.3 has not been finally ratified yet, and as such there are a few servlet containers which support it.
 
Mark Savory
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Expanding Malu's response, HttpServletRequest and HttpServletSession both have setAttribute methods. Is there any reason you can't use both HttpServletRequest.getParameter and HttpServletRequest.getAttribute?
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bala,
How did you test? request.setAttribute(***,***) means these params are available only during this request. Not for the next request.
In other words, you make a call to a servlet, this servlet gets the request with some pre-sent params, say param1, param2, and now you want to set one more 'param3' to request, so you write a code like request.setAttribute("param3","Bala");
and FORWARD this request to a jsp, and inside this jsp again get the param3 as <%request.getAtribute("param3") %>
OR try to get it immediately within the servlet code itself.
I have used this method once and got worked once with Servlet2.2, JSP1.1 with Tomcat3.1.
This is how you tested? Somehow I got a doubt about your testing method. Just wanted to make sure this point. These request.setAttribute(...) are known for only one request not for subsquent ones.
I am not sure about Sevlet2.3's glitch which Frank mentioned.
regds
maha anna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic