我知道有很多类似的问题都有很多答案。但是他们都没有帮我解决这个问题。这就是为什么我决定发布一个新的问题。所以我基本上使用带角度前端的球衣。当我执行我的网址http://localhost:8081/hibernate-jersey-angularjs/rest/leave/list时,它显示404错误"请求的资源不可用"。以下是我的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>index.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>
和webservice:
package com.abc.rest;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.abc.dao.AddLeaveDao;
import com.abc.dao.LeaveDao;
import com.abc.entity.LeaveBalance;
//import com.abc.entity.Love;
import com.abc.entity.LeaveDetails;
@Path("/leave")
public class LeaveWS {
@GET
@Path("list")
@Produces({ "application/json" })
public List<LeaveBalance> list() {
List l= new LeaveDao().getAllLeaves();
return l;
}
@POST
@Path("create")
@Consumes({ MediaType.APPLICATION_JSON})
@Produces({ "application/json" })
public String create(LeaveDetails ld) {
new AddLeaveDao().addDetails(ld);
System.out.println("Returned here");
return "{}";
}
}
和项目结构:
请帮我解决这个问题
答案 0 :(得分:0)
在您的资源中,您的路径映射应以“/”
作为前缀@Path("/list")
@Produces({ "application/json" })
public List<LeaveBalance> list() {
List l= new LeaveDao().getAllLeaves();
return l;
}
如果您使用maven,请执行此更改后,执行mvn clean install以更新资源