Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未在POST方法REST Java中传递参数_Java_Rest_Http_Content Type - Fatal编程技术网

未在POST方法REST Java中传递参数

未在POST方法REST Java中传递参数,java,rest,http,content-type,Java,Rest,Http,Content Type,因此,我正在开发一个web服务,当我在表单提交上调用api/更新操作时,jsp中的两个输入“data”和“id”应该传递,我希望在POST方法块中对其执行操作 以下是调用该方法的表单: <form id="myForm" action="api/update" method="post"> id: <input type="text" id="id" name="id"> <br/> <textarea id="data" name="data" row

因此,我正在开发一个web服务,当我在表单提交上调用api/更新操作时,jsp中的两个输入“data”和“id”应该传递,我希望在POST方法块中对其执行操作

以下是调用该方法的表单:

<form id="myForm" action="api/update" method="post">
id: <input type="text" id="id" name="id">
<br/>
<textarea id="data" name="data" rows="30" cols="100" placeholder="Empty File"></textarea>   
<br/>   
<button id="submit" type="submit">Submit</button>
</form>

身份证件:


提交
以下是剩余代码:

@Path("update")
public class UpdateResource {

    @Context
    private UriInfo context;

    public UpdateResource() {
    }

    @Context
    private HttpServletRequest request;
    @POST
    public void putHtml() {
        String data = request.getParameter("data");
        String id = request.getParameter("id");
        System.out.println(id);   //<---- line1
        System.out.println(data); //<---- line2
        //further operations
    }
}
@Path(“更新”)
公共类更新源{
@上下文
私有信息上下文;
公共UpdateResource(){
}
@上下文
私有HttpServletRequest;
@职位
public-void-putHtml(){
字符串数据=request.getParameter(“数据”);
String id=request.getParameter(“id”);

System.out.println(id);//使用


原因是实体主体已被读取,导致
HttpServletRequest

中的参数为空,html表单的结束标记在哪里?在chrome中运行测试,并在“网络”选项卡上打开开发人员工具,确认数据实际上正在发送到服务器。结束标记没有被删除问题中显示ng。已更正。正在发送数据。我已从“网络”选项卡验证。@KyleM数据正在发送。附加图像使用
@FormParam
,而不是尝试从HttpServletRequest获取参数。即
putHtml(@FormParam(“id”)字符串id)
@peeskillet它起作用了。你能把它作为一个答案发布,这样我就可以接受了。你的答案看起来是正确的,但是你有没有关于“它已经被读取,导致参数为空”的来源?通常,只要属性没有被覆盖或删除,就可以从请求中读取任意次数的属性。@KyleM看了一下。我在其他一些JAX-RS/Jersey相关文档中也读到了一些内容,但我似乎记不起在哪里看到过它
@POST
public void putHtml(@FormParam("id") String id,
                    @FormParam("data") String data) {
}