Tag: jax rs

415尝试在Jax-RSjersey中发送FormData()时的状态

我正在尝试使用jquery ajax发送附加到FormData的文件。 在介绍了一些mozilla和IBM的文档之后,我想出了以下内容。 ajax代码: var sessionId = $.cookie(“referenceId”); var myFormData = { sessionId: sessionId, cipherData: cipherData, // Encrypted xml data payslip: document.getElementById(‘payslip’).files[0]}; var formData = new FormData(); for (var key in myFormData) { console.log(key, myFormData[key]); formData.append(key, myFormData[key]); } $.ajax({ url : ‘api/rootpath/childpath’, type : ‘POST’, processData: false, contentType: false, // Here the contentType is set […]

Java RESTful服务的Jquery调用不工作CORS

我在Tomcat 7上部署了一个rest服务并正在运行。 我可以通过浏览器获取响应数据,但是当我通过jQuery尝试它时,它显示错误。 请检查快照。 @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpRes = (HttpServletResponse) res; //System.out.println(“Client Ip is : “+ SecurityFilter.getClientIpAddr(httpReq)); String domain = new URL(httpReq.getRequestURL().toString()).getHost(); //System.out.println(“Domain is ” + domain); // referrer String referrer = httpReq.getHeader(“referer”); //System.out.println(“Referral URL is -” + referrer); […]

使用JAX-RS和jquery .ajax()检索参数

我正在使用jax-rs编写基本的Web服务。 我正在使用以下JQuery测试应用程序。 我可以使用GET参数访问参数,但是当我使用POST时,它会失败。 我使用以下JQuery来测试只将“POST”切换为“GET”。 $.ajax({ type: “POST”, url: “http://localhost:8080/MyWebService/”, data: ‘text=this is text’, dataType: ‘jsonp’, success: function(data){ console.log(data); }, error: function(){alert(‘failure’);} }); java端看起来如下所示。 请记住,我对获取部分没有任何问题。 @GET public Response getWork(@QueryParam(“callback”) String callbackName, @QueryParam(“text”) String searchText, @Context HttpServletResponse response, @Context HttpServletRequest request) throws JsonGenerationException, JsonMappingException, IOException { System.out.println(searchText); return work(callbackName, searchText, response, request); } @POST public Response postWork(@FormParam(“callback”) […]

带有Jersey / JAX-RS的AJAX JSONP Restful服务

我已经阅读了很多关于stackoverflow的问题,但我没有解决我的问题。 这是我的Restful服务: @GET @Path(“/GetAllProducts”) @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() { return “{\”name\”:\”MAC\”, \”quantity\”:\”10\”}”; } 它在浏览器上工作正常但是当我使用AJAX时,它没有显示错误但显示了一个弹出窗口:失败的对象[对象] 我的AJAX代码: $.ajax({ url: “http://localhost:8080/Restful/REST/WebService/GetAllProducts”, type: ‘GET’, contentType: “application/json; charset=utf-8”, dataType: “jsonp”, success: function() { alert(“Success”); }, error: function(e) { alert(‘Failed! ‘ + e); } }); 我试图添加:“crossDomain:true”但它没有用。 请帮我! 谢谢!