This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

modifying request parameter values  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does any one know if it is possible to modify the parameter values in the request object. Then when the request is forwarded to another servlet, that servlet will read the modified value(s)?
By browsing through the servlet api and the struts api there are no methods to do this. So, I'm looking for some code that reads the input stream, modifies the headers and then forwards that request stream.
Thanks,
Dan
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope I understood what you are asking. But couldn't you wrap the ServletRequest in the java.servlet.http.HttpServletRequestWrapper object, subclass it and provide your implementation of the getParameter(String str) method.
Craig.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, this could be used in conjunction with or not with the javax.servlet.Filter interface.
my $0.02
Craig.
 
Dan Freeman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by cj jack:
I hope I understood what you are asking. But couldn't you wrap the ServletRequest in the java.servlet.http.HttpServletRequestWrapper object, subclass it and provide your implementation of the getParameter(String str) method.
Craig.


I tired sub classing the java.servlet.http.HttpServletRequestWrapper object but I do not have access to the parameter map in it, as it is private or friendly. If I had access to it, I could then modify it and set the parameter values, add/modify values. Seems it would be a handy thing to do. Maybe I'd have to modify the source for this. Or, if the parameter map is friendly I could add a file in the java.servlet.http package and rejar.
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an aside, do you really need to change the parameters? The usual way to accomplish this sort of operation is to process the parameter values and put the results in the request context. As a simple example ...
in the sending servlet/JSP put something like:

then in the destination servlet/JSP do something like:
 
Dan Freeman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank, this is what I wound up doing. I just didn't want to add the logic to the called servlet to do the extra check. I guess modifying the request parameter values directly could have some side effects that could violate the servlet container, or something like that?
It's intersting though, because in Jsp with the tag:
<jsp:include page="/jsp/myJsp.jsp" flush="true" >
<jsp aram name="myParamName" value="<%=myVar%>" />
</jsp:include>
you can add or modify parameters, but you can't do this in servlet code.
Some sort of difference between an include and forwarding a request...
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan wrote: I tired sub classing the java.servlet.http.HttpServletRequestWrapper object but I do not have access to the parameter map in it, as it is private or friendly. If I had access to it, I could then modify it and set the parameter values, add/modify values. Seems it would be a handy thing to do. Maybe I'd have to modify the source for this. Or, if the parameter map is friendly I could add a file in the java.servlet.http package and rejar.
In this situation I would simply add an extra Map to the new "wrapper" class, and override the getParameter method to check my map first:

Does that make sense?
 
Dan Freeman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense, thanks!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!