通过从输入文本框中传递参数,通过 jQuery AJAX 调用 Java EE REST 服务

拉米亚

我有一个 html 代码来创建一个输入文本框,它接受输入表单 user.And 参数必须与 url 一起传递才能休息服务。这是我的ajax调用代码:

$(function() {

var empid = document.getElementById("ManagerId").value;
$('#submit').click(function(){ 
$.ajax({ 
    crossDomain : true,
     type: "GET",
     dataType: "json",
    url: "http://localhost:8088/JirasTrackingApp/reporter/Reportees?empid="+empid,

     success: function(result){        
        console.log(result);
        document.write(empid.value);
     }
 });
});

这是我的服务:

@Path("/Reportees")
public class ReporteesService {
    ReporteeList   reportee = new ReporteeList();

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Map<Object, Object> getList(String empid) throws Exception {
        System.out.println("id is"+empid);  //when I try to print the empid,it  displays nothing
        Map<Object, Object> map=reportee.getReportees(empid);  
        return map;             
    }
});

这是我在 ReporteeList 类中的 getReportees()

public class ReporteeList {

    public Map<Object, Object> getReportees(String idOfEmp) throws Exception {
        System.out.println(idOfEmp);
        String msg = "error";
        String api = "https://connect.ucern.com/api/core/v3/people/";
        String id = idOfEmp;
        String ext = "/@reports";
        String url = api + id + ext;
        String name = "*********";
        String password = "*********";
        String authString = name + ":" + password;
        String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
        System.out.println("Base64 encoded auth string: " + authStringEnc);
        Client restClient = Client.create();
        WebResource webResource = restClient.resource(url);
        ClientResponse resp = webResource.accept("application/json")
                                         .header("Authorization", "Basic " + authStringEnc)
                                         .get(ClientResponse.class);
        if (resp.getStatus() != 200) {
            System.err.println("Unable to connect to the server");
        }
        String output = resp.getEntity(String.class);

        // JSONParser reads the data from string object and break each data into key
        // value pairs
        JSONParser parse = new JSONParser();
        // Type caste the parsed json data in json object
        JSONObject jobj = (JSONObject) parse.parse(output);
        // Store the JSON object in JSON array as objects (For level 1 array element i.e list)

        JSONArray jsonarr_s = (JSONArray) jobj.get("list");
        Map<Object, Object> map = new HashMap<Object, Object>(); //error in this line 

        if (jsonarr_s.size() > 0) {

            // Get data for List array
            for (int i = 0; i < jsonarr_s.size(); i++) {
                JSONObject jsonobj_1 = (JSONObject) jsonarr_s.get(i);
                JSONObject jive = (JSONObject) jsonobj_1.get("jive");
                Object names = jsonobj_1.get("displayName");
                Object userid = jive.get("username");
                map.put(names, userid);                  
            }

            return map;
        } else {
            map.put("errorcheck", msg);
        }
        return map;
    }
}

该值empid从Ajax调用不被采取的服务。请告诉我如何从 url 中捕获参数并将其传递给其他服务。

西亚瓦斯

您还必须@QueryParam为您的getList方法指定注释

@GET
@Produces(MediaType.APPLICATION_JSON)
public Map<Object, Object> getList(@QueryParam("empId") String empid) throws Exception {
    System.out.println("id is"+empid);  //when I try to print the empid,it  displays nothing
    Map<Object, Object> map=reportee.getReportees(empid);  
    return map;             
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用jQuery Ajax调用REST Web服务?

来自分类Dev

处理对WCF REST服务的jQuery AJAX调用的数据部分

来自分类Dev

ASP.Net中的jQuery Ajax调用到SharePoint 2013 REST服务(跨域)拒绝访问

来自分类Dev

从AJAX调用REST服务方法

来自分类Dev

在jQuery mobile中通过Ajax调用PHP Web服务

来自分类Dev

jQuery按钮未通过Ajax触发服务调用

来自分类Dev

jquery ajax在mvc 4中调用Web服务

来自分类Dev

jquery ajax在mvc 4中对Web服务的调用

来自分类Dev

从jQuery .ajax()问题调用Web服务

来自分类Dev

jQuery Ajax无法调用Web服务

来自分类Dev

NodeJS如何通过POST从jquery ajax调用发送的服务器中获取数据

来自分类Dev

等效于curl的REST调用的jQuery AJAX

来自分类Dev

在Java EE中持续运行服务

来自分类Dev

jQuery Ajax 调用传递参数

来自分类Dev

通过jQuery进行AJAX调用

来自分类Dev

通过SSL调用REST Web服务

来自分类Dev

通过 HttpClient 调用 Rest WCF 服务

来自分类Dev

如何使用 Jquery 在 Ajax 调用中调用 Mvc 服务器端验证

来自分类Dev

如何通过AJAX调用AXIS Web服务?

来自分类Dev

Ajax中的Access-Control-Allow-Origin调用jersey rest Web服务

来自分类Dev

在jQuery ajax调用的URL参数中传递:

来自分类Dev

使用$ .ajax()与async时遇到麻烦:错误的调用rest服务

来自分类Dev

jQuery ajax调用以在MVC中传递JSON数组(500内部服务器错误)

来自分类Dev

415通过Ajax调用RESTful Java Web服务时不受支持的媒体类型

来自分类Dev

来自datepicker onSelect的jQuery ajax调用消失了文本框

来自分类Dev

在Phonegap中调用REST服务的正确方法

来自分类Dev

JQuery Ajax:“无效的Web服务调用,缺少参数值:\ u0027Object \ u0027”

来自分类Dev

使用jquery将单个文本框值传递给ajax调用

来自分类Dev

从Servlet调用Rest服务

Related 相关文章

  1. 1

    使用jQuery Ajax调用REST Web服务?

  2. 2

    处理对WCF REST服务的jQuery AJAX调用的数据部分

  3. 3

    ASP.Net中的jQuery Ajax调用到SharePoint 2013 REST服务(跨域)拒绝访问

  4. 4

    从AJAX调用REST服务方法

  5. 5

    在jQuery mobile中通过Ajax调用PHP Web服务

  6. 6

    jQuery按钮未通过Ajax触发服务调用

  7. 7

    jquery ajax在mvc 4中调用Web服务

  8. 8

    jquery ajax在mvc 4中对Web服务的调用

  9. 9

    从jQuery .ajax()问题调用Web服务

  10. 10

    jQuery Ajax无法调用Web服务

  11. 11

    NodeJS如何通过POST从jquery ajax调用发送的服务器中获取数据

  12. 12

    等效于curl的REST调用的jQuery AJAX

  13. 13

    在Java EE中持续运行服务

  14. 14

    jQuery Ajax 调用传递参数

  15. 15

    通过jQuery进行AJAX调用

  16. 16

    通过SSL调用REST Web服务

  17. 17

    通过 HttpClient 调用 Rest WCF 服务

  18. 18

    如何使用 Jquery 在 Ajax 调用中调用 Mvc 服务器端验证

  19. 19

    如何通过AJAX调用AXIS Web服务?

  20. 20

    Ajax中的Access-Control-Allow-Origin调用jersey rest Web服务

  21. 21

    在jQuery ajax调用的URL参数中传递:

  22. 22

    使用$ .ajax()与async时遇到麻烦:错误的调用rest服务

  23. 23

    jQuery ajax调用以在MVC中传递JSON数组(500内部服务器错误)

  24. 24

    415通过Ajax调用RESTful Java Web服务时不受支持的媒体类型

  25. 25

    来自datepicker onSelect的jQuery ajax调用消失了文本框

  26. 26

    在Phonegap中调用REST服务的正确方法

  27. 27

    JQuery Ajax:“无效的Web服务调用,缺少参数值:\ u0027Object \ u0027”

  28. 28

    使用jquery将单个文本框值传递给ajax调用

  29. 29

    从Servlet调用Rest服务

热门标签

归档