escape characters in querystring
Hello all, I have run across the instance where the data that I am passing in the query-string has spaces. The spaces in the query-string are escaped (using %20). I have a class that retrieves the querystring and parses it into a hashmap with key/value pairs. However, when you retrieve the querystring from the request object using getQueryString(), the data is not un-escaped. I could write a simple class the handle this problem, however, I was wondering if there is a better way, or some method in the request, etc, that I am missing. I noticed that the HttpUtils class has the parseQueryString() method, but this has been depricated. Any help would be appreciated, Pete begin:vcard n:; x-mozilla-html:FALSE org:BRIMG SRC="http://www.irista.com/logo/irista.gif"BRBRFONT Color=#80FONT SIZE=2BBringing Vision to Your Supply Chain adr:;; version:2.1 end:vcard
RE: escape characters in querystring
Title: RE: escape characters in querystring However, when you retrieve the querystring from the request object using getQueryString(), the data is not un-escaped. I could write a simple class the handle this problem, however, I was wondering if there is a better way, or some method in the request, etc, that I am missing. While getQueryString gives you the raw query string, the various javax.servlet.ServletRequest.getParameter methods should give you the unescaped/decoded version. It sounds like ServletRequest.getParameter could replace your query string parser/hashtable outright. By the way, the JDK does provide utility methods for encoding and decoding query strings, take a look at java.net.URLEncoder and java.net.URLDecoder (http://java.sun.com/j2se/1.3/docs/api/java/net/URLEncoder.html and http://java.sun.com/j2se/1.3/docs/api/java/net/URLDecoder.html). - rlw
Re: escape characters in querystring
Thanks for the quick response Rodney! Im not sure how I overlooked those classes. I searched JavaSoft for 'escape', and 'query string' and did not find any mention of them. It appears that the query string is automatically encoded (at least for spaces). However, I imagine that it is still a good idea to perform an Encode() for all data that will be passed (in case of special characters). I assume that the , +, etc are NOT automatically encoded, and this is where the Encode() method comes in. Does anyone know where the basic encoding is being performed? (just curious). Thanks again, Pete begin:vcard n:; x-mozilla-html:FALSE org:BRIMG SRC="http://www.irista.com/logo/irista.gif"BRBRFONT Color=#80FONT SIZE=2BBringing Vision to Your Supply Chain adr:;; version:2.1 end:vcard