【问题标题】:Not able to get the output of my Rest Webservices and it is getting HTTP 404 exception无法获得我的 Rest Webservices 的输出,并且出现 HTTP 404 异常
【发布时间】:2018-07-04 11:42:42
【问题描述】:

在执行此程序时,我收到 HTTP 状态 404 异常:

HTTP 状态 404 - /Restful_WebServices_Tuts/test/home
输入状态报告
消息 /Restful_WebServices_Tuts/test/home
描述 请求的资源不可用。
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 World 类

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>

我该如何解决这个问题?

【问题讨论】:

  • /home 你在哪里声明的?
  • 对不起,你好..我提到了家..但即使现在我也尝试过你好......同样的错误正在发生

标签: java rest web-services tomcat


【解决方案1】:

您使用了哪个框架?

如果您的服务器端口号是 8080,请尝试此操作

http://localhost:8080/Restful_WebServices_Tuts/test

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

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

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

【讨论】:

    【解决方案2】:

    您的 Web-Inf\web.xml 中有什么?

    通常有一个&lt;servlet-mapping&gt; 包含一个&lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;

    这必须链接在 url 中,因此,假设您在具有 8080 端口的本地环境中,并为您的 web 方法设置一个特定的 PATH,例如:

    @GET
    @Path("getHelloTest")
        @Produces("text/plain")
        public String HelloWorld(){
    

    你可以:

    http://localhost:8080/YourProjectName/rest/hello/getHelloTest
    

    如果你声明了一个像“/”这样的上下文菜单,你可以从rest uri中排除项目名称。

    【讨论】:

    • 对不起,但我不明白..你能告诉我我必须在我的代码中更改什么吗.. 端口 8080 目前正在使用 SQL,所以我无法使用相同的对于 Apache 服务器.. 所以我使用 8083
    • Hii Web.xml 已添加.. 请检查一次
    • 那个 web.xml 没有指定 rest 规则来尝试从 URL 中排除 /Restful_WebServices_Tuts(假设它的项目名称)。
    • 是的jacj,那是一个项目名称..没有项目名称是否可以排除和执行
    猜你喜欢
    • 2022-07-15
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 2021-11-23
    相关资源
    最近更新 更多