开发者

Get all html form param name & value using jersey

开发者 https://www.devze.com 2023-04-04 20:06 出处:网络
I have a html form which contains elements like this <input type=\"text\" value=\"Val1\" name=\"Name1\"/>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消