I have a html form which contains elements like this
<input type="text" value="Val1" name="Name1"/>
<input type="text" value="Val2" name="Name2"/>
<input type="hidden" value="Val3" name="Name3"/>
On server side, i use Jersey implementation to capture the form name and values. Is there a way to capture all of the above in a single Map like this
Name1 ==> Val1 Name2 ==> Val2 Name3 ==> Val3
I understand that using @FormParam, i开发者_如何学C can capture the form value in a variable . But i need to capture the form element name as well as value.
Any help is appreciated.
Give your method an argument of type MultivaluedMap<String,String>
. Implementations are required to provide a MessageBodyReader
for this type that responds to the media type application/x-www-form-urlencoded
(§4.2.4 of the spec). So something like:
@POST
@Consumes("application/x-www-form-urlencoded")
public Response foo(MultivaluedMap<String, String> form) {
...
}
FYI - You can also use com.sun.jersey.api.representation.Form instead of MultivaluedMap - it is essentially the same thing.
精彩评论