Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServlet Request getParameter automatic converting

 
Jeremy Linzer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having the following issue with getParameter method of HttpServletRequest. I have a JSP which is a for musing POST method. One of the form elements is a radio button that has an ASCII value for a comma, , for its value. For example, <input type="radio" name="radioName" value="Yes, more than 60 days ago" />Yes, more than 60 days ago. When I do a request.getParameter("radioName"); on this the , is converted into an actual comma. Any ideas where exactly this is happening and why and is there anything I can do about this. This happens both on Tomcat and WSAD 5.0?

Thanks
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Jeremy-
Welcome to the JavaRanch! We've got the perflect place for servlet-y questions like this. So I'm going to move this to the Servlets forum. Please continue the conversation there.

As for your question -->
Check out the URLDecoder class. I think it will do the kind of thing you need. It's happening so that the character doesn't get corrupted.

The standard format for URL's with parameters is like this:
blah.com/somepage.jsp?param1=value1¶m2=value2

But what if the value you were sending actually contained a "&" like "Bonnie & Clyde" That could get pretty messy, your request would look like this:

blah.com/somepage.jsp?hero=Davey+Crocket&villain=Bonnie+&+Clyde

How would the application server know that the "&" inside "Bonnie+&+Clyde" was actually part of the value and not a marker to deliniate the next set of name / value pairs?? The solution is to encode all the param names and values with those funky %XX codes so no one gets confused. Make Sense?
 
Jeremy Linzer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
I want to correct something in my original posting The radio button code that I am using is actually <input type="radio" name="radioName" value="Yes&#44; more than 60 days ago" />Yes, more than 60 days ago. The &#44; is getting converted to a regular comma when I do a request.getParameter as in elementValue = request.getParameter(pageElementName);. I tried using the URLDecoder as you suggested and it still didn't work. I am using JDK 1.3 (I have no control over it). as in:
elementValue = request.getParameter(pageElementName);
String decoded = URLDecoder.decode(elementValue);

Any other ideas
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
o -- so you WANT it to stay in the format "Yes&#44; more than 60 days ago" -- and NOT be converted into "Yes, more than 60 days ago" -- right?

I think getParameter() converts things into the normal non-URL encoded format as a convenience....

So, if you'd like to access the raw data, use: request.getQueryString() -- but then its your responsibility to break it up into parameter names and values. But that should be pretty doable with the String.split() method.
[ September 01, 2004: Message edited by: Jessica Sant ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could presumably just re-encode it with java.net.URLEncoder.encode(elementValue, "UTF-8"), but then you'd get the pluses for spaces, etc. If you don't want the whole thing encoding you could just use String.replace() for the comma.
 
Jeremy Linzer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your responses. THey were a big help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic