I have some html forms which have select inputs that can have multiple values selected. When I post them to my Restlet service I only the currently selected value. I know that if this were a plain servlet I could use request.getParameterValues(... to get to the array of selected values, but I can't seem to find the equivalent in Restlet. From what I can tell the service maps the request to a JsonRepresentation but I don't see an equivalent method for accessing the parameter values.
Does anyone know a way to do this with Restlet2.x?
In fact, it depends on the way you post the form from the client. Your question lets me think that you use URL encoded form ( Content-Type: application/x-www-form-urlencoded
).
In this case, you can extract the submitted data using the class Form
of Restlet, as described below:
public class MyServerResource extends ServerResource {
@Post
public void handleForm(Form myForm) {
// Equivalent from request#getParameterValues for Servlet
String[] values = myForm.getValuesArray("mykey");
(...)
}
}
If you want to get a query parameter, simply use the method getQuery
to get the associated form object:
public class MyServerResource extends ServerResource {
@Post
public void handleForm(Form myForm) {
// Equivalent from request#getParameterValues for Servlet
String[] values = getQuery().getValuesArray("mykey");
(...)
}
}
Hope it helps you, Thierry
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.