gpt4 book ai didi

java - jersey/tomcat 说明源服务器未找到目标资源的当前表示

转载 作者:搜寻专家 更新时间:2023-10-31 19:59:48 24 4
gpt4 key购买 nike

我已经根据此处描述的细节配置了 jersey(带有 tomcat 服务器),直到步骤 6.3: http://www.vogella.com/tutorials/REST/article.html#jerseyprojectsetup

下面是我的 web.xml 文件,唯一的区别是 jersey.config.server.provider.packages

的路径/包名称

说明有;

<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>

因为 com.vogella.jersey.first 是他们的包名,而我选择将我的指向我的默认包 (jerseytest)

但这是我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jerseytest</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Register resources and providers under com.vogella.jersey.first package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>jerseytest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

当我在 tomcat 服务器上运行应用程序时,我不断收到:

HTTP Status 404 – Not Found

Type Status Report

Message /jerseytest/

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.23

当我将浏览器指向教程中提到的终点时:http://localhost:8080/com.vogella.jersey.first/rest/hello

我收到一个未找到的错误:

HTTP Status 404 – Not Found

Type Status Report

Message Not Found

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.23

当我将浏览器直接指向 http://localhost:8080/rest/hello

我得到:

HTTP Status 404 – Not Found

Type Status Report

Message /rest/hello

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.23

我的 java 类与说明中的示例相同,只是我的类在默认包中:

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

// Plain old Java Object it does not extend as class or implements
// an interface

// The class registers its methods for the HTTP GET request using the @GET annotation.
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.

// The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {

// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}

// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}

// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}

}

最佳答案

这个问题我纠结过很多次。

我目前使用的解决方案是 webapp(或您保存 jsp 等 View 的文件夹)在部署程序集下。

这样做右键单击 project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder >(添加你的 jsp 文件夹。默认情况下是 src/main/webapp)

关于java - jersey/tomcat 说明源服务器未找到目标资源的当前表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47585068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com