我是新手,但我正在尝试用Java创建一个Web服务,但当我尝试使用Web服务访问任何方法时,它会给我一个404错误
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>Start</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>com.mycompany.lecture.LectureServices</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Start</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
</web-app>
这是我的网络服务LectureServices.java:
package com.mycompany.lecture;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/services")
public class LectureServices {
@GET
@Path("/sayhello")
@Produces(MediaType.TEXT_PLAIN)
public String ViewAll() {
return "Hello im here";
}
}
我正在通过此链接http://localhost:8084/Lecture/app/services/sayhello对Postman进行测试,它给出了404错误,但http://localhost:8084/Lecture/正在查看我的index.html
谁能告诉我,我做错了什么?