Search code examples
javaajaxjersey-2.0jersey-clienttom

Jersey throws Bad request exception(400)


While trying to get single record from database jersey throws Bad request exception.Kindly somebody help me to fix that.

Ajax :-

     var id = $(this).attr("data-id").trim();
    $.ajax({
        url:"./scalegdn/service/getServiceById/"+id,
        method:"get",
        dataType:"json",
        success:function(data){
            $("#servicename").val(data.serviceName);
            $("#description").val(data.serviceDescription);
        }
    });

Jersey resource :-

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/getServiceById/{id}")
public ServiceTO getServiceById(@PathParam("id") int id) throws Exception {
    ServiceDAO servicedao = null;
    ServiceTO service=null;
    logger.info("id is:"+id);
    try {
        service=servicedao.getServiceById(id);
    } catch (Exception e) {
        logger.error("Error occurs,While trying to get service by serviceId.",e);
    } finally {
        if (!connection.isClosed()) {
            connection.close();
        }
    }
    return service;
}

Solution

  • check @PathParam package your imported. try to use jersey dependency.