我创建了web动态项目,上下文名称是“restJeresy”。并在我的本地使用websphere liberty服务器。
当我点击网址时 http://localhost:9080/restJeresy/TestRestService/callService显示错误
Error 404: Not Found
任何人都可以帮助我,我缺少什么?
这是我的代码,
package com.demo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/TestRestService")
public class HelloWorldService {
@Path("/callService")
@GET
public String getMsg() {
return "Hello World !! - Jersey 2";
}
}
Web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>restJeresy</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey RESTful 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.demo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
web.xml中servlet映射的问题。请检查
server "default" {
listen on 0.0.0.0 port 80
fastcgi socket ":3031"
}
然后尝试访问http://localhost:9080/restJersey/restf/TestRestService/callService