【问题标题】:New to Jersey -- Getting Unsupported Media Type at Resource新泽西州的新手——在资源处获取不受支持的媒体类型
【发布时间】:2011-09-16 22:14:42
【问题描述】:

我是 Jersey 和 REST 的新手,所以如果我的问题太愚蠢,请见谅。我有一个名为 Places 的简单资源,它应该支持 GET 操作,该操作根据输入变量返回一些兴趣点。这是输入字符串和类:

错误:

HTTP 415 - Unsupported Media Type

输入网址:

http://localhost:8080/RESTGO/rest/places?latitude=2&longitude=3&radius=3&types=food

类:

@Path("/places")
public class Places {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public JSONObject getPlaces(@QueryParam("latitude") double latitude,
            @QueryParam("longitude") double longitude,
            @QueryParam("radius") int radius,
            @QueryParam("types") String types,
            @DefaultValue("true") boolean sensor) {
        GooglePlacesClient google = new GooglePlacesClient();
        JSONObject json = null;

        try {
            String response = google.performPlacesSearch(latitude, longitude, radius, types, sensor);
            json = new JSONObject(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}

【问题讨论】:

  • 您接受application/json 机构吗?将 http-header 设置为 application/json(标头名称:Accept,值 = application/json

标签: json rest jax-ws jersey


【解决方案1】:

请确保 [url] 的其余部分映射到您的 web.xml 中

http://localhost:8080/RESTGO/**`*rest*`**/places

【讨论】:

    【解决方案2】:

    如果没有@QueryParam@DefaultValue 将无法工作。尝试将@QueryParam 注释添加到sensor-argument(参见DefaultValue javadoc

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 2017-07-16
      相关资源
      最近更新 更多