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).

4

2 回答 2

1

在您的 Restlet 中,您可以使用以下方法获取查询参数:

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

您从该调用获得的对象提供对所有查询参数的访问,无论是通过名称还是索引。

如果我通常使用的每个查询参数只有一个值:

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

最后的 true 指定参数名称不区分大小写。

于 2012-04-03T04:30:12.050 回答
0

不熟悉reslets。但是,如果您有权访问 HttpServletRequest 对象,则可以使用getParameterMap方法。此方法将返回一个 Map,它允许您使用 getKeySet 方法访问参数名称。请务必注意,返回的 Map 使用字符串数组作为其值类型,而不是普通字符串(这样您就可以看到多个具有相同名称的参数)。

于 2010-04-12T21:27:57.987 回答