MAO-EYE 2014-05-21 18:09 采纳率: 100%
浏览 35

restFul Web服务方法

I want to pass like a parameter an Array to RESTful webservice with Jersey. I have one mutiple select form where users can select multiple options. Then i pass the selected values using AJAX to the RESTful webservice.

That's the select:

<select id="u" multiple class="form-control">                       
 <option value="1">1</option>                   
 <option value="2">2</option>                   
 <option value="3">3</option>
</select>

The jquery js:

$('#send').on('click', function() {
        $.ajax({
            url: "/pc/ws/ms/save-options",
            contentType: "application/x-www-form-urlencoded",
            cache: false,
            type: "POST",
            data: {
                ur: $('#u').val()
            }
        });
    });

I don't know how to indicate on the web service method receive is a array

  • 写回答

1条回答 默认 最新

  • hurriedly% 2014-05-21 19:17
    关注

    If you are using Maven and Jersey we can maybe add this maven dependency which include Jackson lib :

    <properties>
        ...
        <dependency.jersey.version>1.18.1</dependency.jersey.version>
        ...
    </properties>
    

    +

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>${dependency.jersey.version}</version>
    </dependency>
    

    and a code similar to this one (not tested !) would maybe do the trick :

    @POST
    @Path("/save-options")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response getMyValues(Collection<Integer> values) {
        // Do whathever I want with my values
        ...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看