Get all html form param name & value using jersey

自古美人都是妖i 提交于 2019-12-13 12:17:07

问题


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.


回答1:


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) {
    ...
}



回答2:


FYI - You can also use com.sun.jersey.api.representation.Form instead of MultivaluedMap - it is essentially the same thing.



来源:https://stackoverflow.com/questions/7406921/get-all-html-form-param-name-value-using-jersey

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!