REST Jersey Tomcat 7

Getting 404 error while accessing

Hello.java

package de.vogella.jersey.first;
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> ";
  }

} 
'

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>de.vogella.jersey.first</display-name>
      <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
          <param-name>com.sun.jersey.config.property.packages</param-name>
          <param-value>de.vogella.jersey.first</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> 

This was taken from http://www.vogella.com/tutorials/REST/article.html , but when I run http://localhost:8080/de.vogella.jersey.first/rest/hello

. I get a 404 error.

Can anyone help me with this.

+4
source share
3 answers
+1
source

I finished this tutorial and successfully ran your example.

: , , 4 , . jersey 2.0.

:

  • -, jersey-archive-1.16.
    com.sun.jersey.spi.container.servlet.ServletContainer, web.xml
  • -: , - de.vogella.jersey.first. eclipse: org.eclipse.wst.common context-root.
  • , , , , - : asm.jar, jersey-core.jar, jersey-server.jar, jersey-servlet.jar.

+1

Grzesiek D, .

  • jersey-archive-1.16. com.sun.jersey.spi.container.servlet.ServletContainer, web.xml

  • , de.vogella.jersey.first. eclipse: org.eclipse.wst.common - .

*** -rrot, :

(i) " -".

(ii) " " "". Eclipse -

(iii) "" > " " > "".

(iv) , ( " " ) - , "".

(v) On the server you want to use, click context-click to select "Clear ..."

(vi) Click OK in this confirmation dialog. ***************

  • And, of course, make sure that your project compiles correctly and classes at least four banks :. Asm.jar, jersey-core.jar, jersey-server.jar, jersey-servlet.jar
0
source

Source: https://habr.com/ru/post/1523890/


All Articles