1

I'm trying to make a calculator web service that has more than 10 parameters. Is there any function in the Java Restlet or in Java itself that allows you to see the parameter ids?

e.g. http://mywebsite.com/calculator?id1=value1&id2=value2&id3=value3 => I'm trying to access the values of id1, id2, and id3 so that I don't have to require people using the web service to input all parameters (some of them are likely to be 0).

2 Answers 2

1

Inside your Restlet you can get the query parameters using:

this.getRequest().getResourceRef().getQueryAsForm()

The object that you obtain from that call provides access to all of the query parameters, either by name or index.

If there should only be one value for each query parameter I usually use:

String value1 = this.getRequest().getResourceRef().getQueryAsForm().getFirstValue("id1", true);

The true at the end specifies that the parameter name is not case sensitive.

Sign up to request clarification or add additional context in comments.

Comments

0

Not familiar with reslets. However, if you have access to the HttpServletRequest object you can make use of the getParameterMap method. This method will return a Map, which will allow you to access the parameter names using the getKeySet method. Be sure to take note that the Map that is returned uses a string array as its value type and not an ordinary string (this is so you can see multiple parameters which have the same name).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.