Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.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 从请求对象检索具有Jersey的路径参数_Java_Rest_Jersey - Fatal编程技术网

Java 从请求对象检索具有Jersey的路径参数

Java 从请求对象检索具有Jersey的路径参数,java,rest,jersey,Java,Rest,Jersey,我使用Jersey调用了REST API,如下所示: @GET @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) @Path("/get/{version}") public String getData(@PathParam("version") String version, FormDataMultiPart request) { // My code here } 事实

我使用Jersey调用了REST API,如下所示:

@GET
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/get/{version}")
public String getData(@PathParam("version") String version, FormDataMultiPart request) {

    // My code here
}
事实上,我想要两者:

 1) The version set into the URL (like it is now)
 2) The version retrieved from the request object.
 I don't want to have two separate inputs.

有什么方法可以做到这一点吗?

假设您正在使用jQuery和AJAX触发请求,那么您可以这样做:

var vesrion = <retrieve vesrion>
var requestURL = "http://required.url/" + version

$.ajax({
            type : 'POST',
            url : rquestURL,
            cache:false,
            processData:false,
            contentType:false,
            data : new FormData($("#"+formId)[0]) // 'formId' will be the ID of your form           
       }) ..
var-vesrion=
var requestURL=”http://required.url/“+版本
$.ajax({
键入:“POST”,
网址:rquestURL,
cache:false,
processData:false,
contentType:false,
数据:新表单数据($(“#”+formId)[0])/“formId”将是表单的ID
}) ..

这就是如何同时传递路径参数和表单数据的方法。

它可以是任何客户机,所以我认为这行不通。例如,浏览器中的一个简单rest客户端。您能详细说明“我不想有两个单独的输入”是什么意思吗?