jersey/tomcat说明原始服务器找不到目标资源的当前表示形式 [英] jersey/tomcat Description The origin server did not find a current representation for the target resource

查看:1255
本文介绍了jersey/tomcat说明原始服务器找不到目标资源的当前表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已根据此处描述的详细信息配置了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状态404 –找不到

类型状态报告

Message /jerseytest/

说明原始服务器未找到当前表示 目标资源或不愿意透露其存在.

Apache Tomcat/8.5.23

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

我收到未找到的错误:

HTTP状态404 –找不到

类型状态报告

Message Not Found

说明原始服务器未找到当前表示 目标资源或不愿意透露其存在.

Apache Tomcat/8.5.23

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

我得到:

HTTP状态404 –找不到

类型状态报告

Message /rest/hello

说明原始服务器未找到当前表示 目标资源或不愿意透露其存在.

Apache Tomcat/8.5.23

我的java类与说明中的示例相同,不同之处在于我的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之类的视图的文件夹)处于部署组装状态下.

为此 右键点击project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp folder. In default case it is src/main/webapp)

I have configured jersey (with tomcat server) according to the details described until step 6.3 here: http://www.vogella.com/tutorials/REST/article.html#jerseyprojectsetup

Below is my web.xml file, the only difference is that the path/package name for the jersey.config.server.provider.packages

the instructions has;

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

because com.vogella.jersey.first is their package name, while I chose to point mine to my default package (jerseytest)

but this is my 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>

when I run the application on the tomcat server I keep getting:

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

and when i point the browser to the end point mentioned in the tutorial : http://localhost:8080/com.vogella.jersey.first/rest/hello

I get a not found error:

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

When I point the browser directly to http://localhost:8080/rest/hello

I get:

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

My java class is identical to the example in the instructions , except that mine is in the default package :

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> ";
  }

}

解决方案

I struggled with this problem many times.

The solution I am currently using is weather the webapp(or the folder where you kept the views like jsp) is under deployment assembly.

To do so Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp folder. In default case it is src/main/webapp)

这篇关于jersey/tomcat说明原始服务器找不到目标资源的当前表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆