I want to pass like a parameter an Array to RESTful webservice with Jersey. I have one mutiple select form where users can select multiple options. Then i pass the selected values using AJAX to the RESTful webservice.
That's the select:
<select id="u" multiple class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
The jquery js:
$('#send').on('click', function() {
$.ajax({
url: "/pc/ws/ms/save-options",
contentType: "application/x-www-form-urlencoded",
cache: false,
type: "POST",
data: {
ur: $('#u').val()
}
});
});
I don't know how to indicate on the web service method receive is a array
If you are using Maven and Jersey we can maybe add this maven dependency which include Jackson lib :
<properties>
...
<dependency.jersey.version>1.18.1</dependency.jersey.version>
...
</properties>
+
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${dependency.jersey.version}</version>
</dependency>
and a code similar to this one (not tested !) would maybe do the trick :
@POST
@Path("/save-options")
@Consumes(MediaType.APPLICATION_JSON)
public Response getMyValues(Collection<Integer> values) {
// Do whathever I want with my values
...
}
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.