无法使用jquery调用Jersey服务



我正在尝试使用JQuery连接到Jersey服务。但是,它没有连接到服务,因为我在检查日志,它是否已经连接到服务。有什么东西丢了吗?

$('#update').click(function() {
    alert("updating the labelll");
    $.ajax({
        url:"/updatecontent",
        type: 'POST',
        dataType:"json",
        data:$( "#labels option:selected" ).text(),
        async:false,
        success:function(contentdata) { // Success Call Back Function.
            if(contentdata == "1") {
                alert("successfully updated");
            } else {
                alert("sorry.. failed in updating");
            }
        },
        error:function(){ // Error Call back function.
            alert("sorry.. failed in updating in Error call back");
        }
    });
});

服务---------

@Path("/updatecontent")
public class updatecontent {
private static final org.slf4j.Logger     LOGGER=org.slf4j.LoggerFactory.getLogger(updatecontent.class);
@Context
HttpServletRequest request;
@Context
HttpServletResponse response;
@POST
@Consumes(MediaType.APPLICATION_JSON)
public String updateStatus(String packet) throws JSONException {
    // Get the object from the UI.
    LOGGER.info("In the API class of updating content for review.");
    return "1";
}
}

 Web.xml 
---------
 <servlet>
 <servlet-name>jersey-serlvet</servlet-name>
 <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
 <init-param>
  <param-name>com.sun.jersey.config.property.packages</param-name>
  <param-value>net.my.services</param-value>
 </init-param>
 <init-param>
    <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
    <param-value>true</param-value>
 </init-param>
 <load-on-startup>6</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
 <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

我在这里错过了什么吗?应该有个小问题。

您的web.xmlurl-pattern

<url-pattern>/rest/*</url-pattern>
所以jQuery必须连接到
/rest/updatecontent

最新更新