GET 405 405(方法不允许)错误

时间:2017-06-12 09:41:14

标签: angularjs jersey jax-rs jersey-2.0

我正在使用带有jersey后端的angularjs。我正在使用$ http post方法从angular发送一个http请求,我正在尝试使用POJO类在后端解析它。基本上我的控制器使用post方法将密钥发送到后端后端将从数据库返回关于该密钥的数据列表。但是当我尝试这样做时,我得到了错误 “GET http://localhost:8081/hibernate-jersey-angularjs/rest/leave/list 405(方法不允许)”

以下是我的鳕鱼

@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;
	}

和我的控制器

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");
    })
});

和我的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>

请帮忙。

1 个答案:

答案 0 :(得分:0)

在您的代码中,您的资源使用@Post注释,这意味着您只能通过Post方法调用此资源。