I am using angularjs with jersey backend.I am sending a http request from angular using $http post method and i am trying to parse it in the backend using POJO class.Basically my controller sends key to the backend using post method and the backend will return list of data regarding that key from the database.But when i try to do this i get the error " GET http://localhost:8081/hibernate-jersey-angularjs/rest/leave/list 405 (Method Not Allowed)"
Following is my cod
@POST
@Path("/list")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({ "application/json" })
public List<LeaveQueue> list(numPojo s) {
List<LeaveQueue> l= new ShowLeaveDao().getAllLeaves();
Iterator i=l.iterator();
while(i.hasNext())
{
LeaveQueue m=(LeaveQueue)i.next();
System.out.println(m.getNum());
}
return l;
}
and my controller
app.controller("MyDbController", function($scope, $http,mynum,myname) {
//$scope.data = [{title: 'welcome hello'},{title: 'great testing'}];
$scope.test={};
test.num=mynum;
var jsonData=JSON.stringify(test);
console.log("InsideListController"+jsonData);
$http({
url:"rest/leave/list",
method:"POST",
data: jsonData,
headers: {'Content-Type': 'application/json'}
}).success(function(data, status, headers, config) {
$scope.data = data;
}).error(function(data, status, headers, config) {
alert("error from leave list controller");
})
});
and my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container, see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<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_2_5.xsd" version="2.5">
<welcome-file-list>
<welcome-file>trial.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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.abc.rest</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>
Please help .