在执行这个程序时,我得到 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/