如何将多个HTML5表单数据发布到单个REST服务?

时间:2016-03-20 17:05:39

标签: javascript java html5 rest post

我有一个HTML5页面,上面有两个表单,发布到同一个REST服务:

<html>
<body>
    <form id="formOne" action="/v1/info">
        <input type="text" name="name"/>
        <button type="submit">Submit</button>
    </form>
    <form id="formTwo" action="/v1/info">
        <input type="text" name="someOtherInfo"/>
        <button type="submit">Submit</button>
    </form>
</body>
</html>


@Path("/v1/info")
@Component
public class V1Services {    

    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public static Response storeInfo(
        @Context HttpServletResponse response,
        @Context HttpServletRequest request,
        @FormParam("name") String name,
        @FormParam("someOtherInfo") String someOtherInfo,
        ...
}

当用户提交其中任何一个表单时,我想从两个表单中发送数据。将这两种形式合并为一种形式将需要大量工作来重新设计网站的布局,我希望稍后这样做。

是否可以将这两种表单中的数据提交到REST服务,而无需将它们合并到单个HTML5表单中?

0 个答案:

没有答案