Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all html form param name & value using jersey

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

like image 327
prashant Avatar asked May 13 '26 22:05

prashant


1 Answers

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) {
    ...
}
like image 57
Artefacto Avatar answered May 15 '26 11:05

Artefacto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!