获取所有html表单参数名称&使用球衣的价值 [英] Get all html form param name & value using jersey
问题描述
我有一个html表单,其中包含这样的元素
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"/>
在服务器端,我使用Jersey实现来捕获表单名称和值.有没有办法像这样
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 名称2 ==> Val2 名称3 ==> Val3
Name1 ==> Val1 Name2 ==> Val2 Name3 ==> Val3
我了解使用@FormParam可以捕获变量中的表单值.但是我需要捕获表单元素的名称以及值.
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.
感谢您的帮助.
推荐答案
为方法提供类型为MultivaluedMap<String,String>
的参数.需要实现为该类型提供MessageBodyReader
,以响应媒体类型application/x-www-form-urlencoded
(规范的第4.2.4节).像这样:
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) {
...
}
这篇关于获取所有html表单参数名称&使用球衣的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!