如何使用Jersey读取RESTful服务的POST参数? [英] How do I read POST parameters for a RESTful service using Jersey?

查看:397
本文介绍了如何使用Jersey读取RESTful服务的POST参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用JSON或类似的东西。我有一个简单的表单来上传文件,我想读取表单的参数。下面的代码没有按预期工作。它不会显示任何参数。

I am not using JSON or anything like that. I have a simple form to upload a file and I want to read the parameters of the form. The code below is not working as expected. It will not show any parameters.

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{appNum}/{docId}/file")
public Response uploadDocFile(
        @PathParam("appNum") String appNum,
        @PathParam("docId") String docId,
        @Context HttpServletRequest req)
{

    try {

        log.info("POST Parameters:");

        Enumeration e = req.getParameterNames();

        while(e.hasMoreElements())
        {
            Object key = e.nextElement();
            log.info("Key: " + key);
            log.info("Val: " + req.getParameter(key.toString()));
        }


    }  catch (Exception e) {
        e.printStackTrace();
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(new StatusResponse(e)).build();
    }

    return Response.ok().build();
}


推荐答案

仅供参考,你需要使用@FormParam。还要确保INPUT HTML类型使用name = not id =。

FYI, You need to use @FormParam. Also make sure INPUT HTML types are using name= not id=.

这篇关于如何使用Jersey读取RESTful服务的POST参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆