Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.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
Java 在Restful服务中获取HttpServletResponse Null_Java_Rest_Servlets - Fatal编程技术网

Java 在Restful服务中获取HttpServletResponse Null

Java 在Restful服务中获取HttpServletResponse Null,java,rest,servlets,Java,Rest,Servlets,我正在使用REST服务进行测试,需要从中获取HttpServletResponse对象 当我这样调用函数时: 我得到的HttpServletResponse总是空的 @Path("/testify") @GET @Produces(MediaType.APPLICATION_JSON) public Response Testify(HttpServletResponse response) throws Exception { try { return Utiliti

我正在使用REST服务进行测试,需要从中获取
HttpServletResponse
对象

当我这样调用函数时:

我得到的
HttpServletResponse
总是空的

@Path("/testify")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response Testify(HttpServletResponse response) throws Exception {
    try {
        return Utilities.getSvc(true, "OK");

    } catch (Exception e) {
        return Utilities.getSvc(false, "ERROR");
    }
}

有什么我遗漏的吗?

我终于做到了,只需要将
@Context
注释放到
HttpServletResponse
对象中,并添加一个
HttpServletRequest
参数:

@Path("/testify")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response Testify(@Context HttpServletResponse response, 
                        @Context HttpServletRequest request) throws Exception {
    try {
        return Utilities.getSvc(true, "OK");

    } catch (Exception e) {
        return Utilities.getSvc(false, "ERROR");
    }
}
也许会有帮助。