ecuguru
asked on
Java parse URL params
Hi,
Can someone tell me how I can parse Get values from a REST request like:
http://server.com/?&tag1=value1&tag2=value2...
There's gotta be a lib or something to let me break it down to an array and get something like:
value1 = array[tag1];
Can someone tell me how I can parse Get values from a REST request like:
http://server.com/?&tag1=value1&tag2=value2...
There's gotta be a lib or something to let me break it down to an array and get something like:
value1 = array[tag1];
You can get a listing of parameter names OR if you use same parameter name like:
tag=value1&tag=value2&tag= value3
You can get an array using the getParameterValues, otherwise you have to get each param specifically like FarzadA has shown.
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html
tag=value1&tag=value2&tag=
You can get an array using the getParameterValues, otherwise you have to get each param specifically like FarzadA has shown.
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html
ASKER
My java app handles web requests, it's not a servlet.
Is there a way to make this work without the servlet aspect?
Is there a way to make this work without the servlet aspect?
Maybe this will be more helpful for REST.
http://developer.yahoo.com/java/howto-parseRestJava.html
So are you getting the entire request as a string as shown in example?
http://developer.yahoo.com/java/howto-parseRestJava.html
So are you getting the entire request as a string as shown in example?
ASKER
Yep.. I'm getting a string that is:
URLString = "http://localhost/server?&value1=value1&value2=value2"
And I'd like to parse for the values.. I'm putting it into a new URL, but can't find a good parser lib yet.
URLString = "http://localhost/server?&value1=value1&value2=value2"
And I'd like to parse for the values.. I'm putting it into a new URL, but can't find a good parser lib yet.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is sample code:
public class ExampleServlet extends HttpServlet {
protected void service(HttpServletRequest
throws ServletException, IOException {
String param1 = request.getParameter("tag1
// Now param1 holds value1
}
}