【问题标题】:GET 405 405 (Method Not Allowed) errorGET 405 405(不允许的方法)错误
【发布时间】:2017-11-13 17:44:39
【问题描述】:

我正在使用带有 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>

请帮忙。

【问题讨论】:

  • 听起来是个错误的网址,请检查您的网址是否正确

标签: angularjs jersey jax-rs jersey-2.0


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-12-20
  • 1970-01-01
  • 2016-12-02
  • 2015-11-25
  • 2016-01-31
  • 2013-03-23
  • 1970-01-01
  • 2012-10-25
相关资源
最近更新 更多