This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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?
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, more than 60 days ago" />Yes, more than 60 days ago. The , 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);
o -- so you WANT it to stay in the format "Yes, 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 ]
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.