<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>mvc_1</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>Jersey</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>org.user</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app>
var sUsername = $("#tbUsername").val(); var sPassword = $("#tbPassword").val(); var jsonObj = {"username":sUsername,"password":sPassword}; $.ajax ({ url:"http://localhost:8080/mvc_1/rest/controller/doPosting", type:'POST', dataType:'json', data:JSON.stringify(jsonObj), contentType: "application/json; charset=utf-8", success: function(data) { alert("success!!") }, error:function(XHR,status,er) { alert(XHR.status +" : "+er+" : "+status); } });
@Path("/controller") public class UserController { @POST @Path("/doPosting") @Consumes({ MediaType.APPLICATION_JSON }) public String doPosting(User user) { String output = user.getUsername(); System.out.println(output); String json = new Gson().toJson(user); System.out.println("Hi"); return json; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)