I have written my ajax
post
in my Java Script
file like this:
Where obj1 is a Stringified
JSON
object.
$.ajax({
url:'./rest/input/post',
type: 'POST',
data:obj1,
contentType: 'application/json',
dataType:'json',
success:function(data)
{
var values = JSON.stringify(data);
alert(values);
},
},'json');
I am passing it to a Java
class which is as below:
@Path("/input")
public class InputResponse {
@POST
@Path("/post")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Input postInputRecord(Input obj){
return obj;
}
}
My Web.xml
file is as below:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<display-name>CAD</display-name>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.cad.example.response</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.cad.data.model</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This is the maven
project:
I am running it on a Jetty
Server
, while invoking a url "http://localhost:8001/project_name/rest/input/post"
But it is giving me 404
error. There is no error in console except this.
Why is it so? How can I solve this?
Any suggestion much appreciated.