Is there a nice method in a request object that would load a query string into a hashtable or something similar? There seems to be similar functionality in the getParameterNames for form elements (text inputs etc.) but not for query string. Or am i just wrong? thanks in advance paul
sorry for the ambiguity. The query string that is passed in the url. That is, if you look at the address/location of this web page in your browser it is something like: "http://www.eporkchop.com/cgi-bin/cgiwrap/~banana/postings.cgi?action=repley&form=+++servlets...". well every thing past the ? is the query string where we have keys "action" and "form" and values "reply" and "servlets" where key action goes w/ reply... what i want is to get these keys and values into a hashtable or at least get an enumeration of the keys and then access them thru a request method much like that of parameters and header (getParameterValue(name)). thanks for your attention to this subject. paul
The method ServletRequest.getParameterNames() returns an Enumeration of the names from both the URL query string and the post data if present. It's pretty easy to loop through this and access all the named parameters. The reason that it's not available as a Hashtable is that it can be a one-to-many relationship between name and value. Consider the simple URL:
This is perfectly valid, but has two values for "a". Duplication like this can also appear in the POST data, so you need to be careful with your servlet design to make sure this is handled properly. The best place to look for example code is in SnoopServlet.java, provided in the examples directory of most JSDK downloads. This extracts and displays just about everything it can from the request and the context.