rest – 如果动态创建表单元素,如何使用@FormParam

rest – 如果动态创建表单元素,如何使用@FormParam,第1张

概述由于在此应用程序中动态创建html表单元素,因此不知道元素的数量.如何使用@FormParam注释获取元素信息?例如,以下代码获取两个表单元素的信息: @POST @Path("/newpage") @Produces("text/html") public String func(@FormParam("element1") String firstElement, 由于在此应用程序中动态创建HTML表单元素,因此不知道元素的数量.如何使用@FormParam注释获取元素信息?例如,以下代码获取两个表单元素的信息:

@POST    @Path("/newpage")    @Produces("text/HTML")    public String func(@FormParam("element1") String firstElement,@FormParam("element2") String secondElement) throws IOException     {         // your code goes here    }

这是不可能的,因为我们不知道元素的数量.

解决方法 我想不出使用@FormParam这样做的方法,但你可以使用 @Context访问httpServletRequest(它引用所有表单参数的映射):

// you can make this a member of the Resource class and access within the Resource methods@Contextprivate httpServletRequest request;@POST@Path("/newpage")@Produces("text/HTML")public String func() throws IOException {    // retrIEve the map of all form parameters (regardless of how many there are)    final Map<String,String[]> params = request.getParameterMap();    // Now you can iterate over the key set and process each fIEld as necessary    for(String fIEldname : params.keySet())    {        String[] fIEldValues = params.get(fIEldname);        // your code goes here    }}
总结

以上是内存溢出为你收集整理的rest – 如果动态创建表单元素,如何使用@FormParam全部内容,希望文章能够帮你解决rest – 如果动态创建表单元素,如何使用@FormParam所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1068208.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存