java - 无法获取我的 Rest Webservices 的输出,并且出现 HTTP 404 异常

标签 java rest web-services tomcat

在执行这个程序时,我得到 HTTP Status 404 异常:

HTTP Status 404 - /Restful_WebServices_Tuts/test/home
type Status report
message /Restful_WebServices_Tuts/test/home
description The requested resource is not available.
Apache Tomcat/8.0.36

这是我的应用类

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/test")
public class JAX_RS_Starter extends Application{

}

这是我使用 GET 注释的 Hello 世界类

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;

import java.lang.String;


@Path("/hello")
public class HelloRS{
    @GET
    @Produces("text/plain")
    public String HelloWorld(){
        return "Hello World";
    }
}

还有我的 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" version="3.1">
  <display-name>Restful WebServices Tuts</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>
</web-app>

我该如何解决这个问题?

最佳答案

您使用的是哪个框架?

如果你的服务器端口号是8080请试试这个

http://localhost:8080/Restful_WebServices_Tuts/test

如果你使用 Liferay 框架试试这个

http://localhost:8080/o/Restful_WebServices_Tuts/test

希望你能发现自己的错误。 希望对您有所帮助。

关于java - 无法获取我的 Rest Webservices 的输出,并且出现 HTTP 404 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48439246/

相关文章:

java - 如何将 JPA 对象从 App Engine 发送到 GET?类型 'org.datanucleus.store.types.sco.simple.Date'

java - 通过父类(super class)对象的 ArrayList 访问子类方法?

java - header 位置不重定向

java - 将异常从 CXF 拦截器传播到异常映射器

wcf - 使用 WCF 服务域模型进行延迟加载?

java - 使用服务创建基于 Java Spring MVC 3 的应用程序,

java - 如何添加性感的开/关 slider ?

java - 这个 Spring Security 示例究竟是如何工作的?

java - 从 CSR 文件获取 SSL 证书

java - 托管基于 Java 的 REST API 服务