【发布时间】: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