rest example

hi,

trying below example

https://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/

HTTP Status 404 – Not Found


Type Status Report

Message /RESTfulExample/

getting below error

http://localhost:8080/RESTfulExample/

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

please advise
LVL 7
gudii9Asked:
Who is Participating?
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
None of that really makes sense, but let me have a wild guess at what you are asking...

how it is mapping?

Are you asking why the different path components are necessary? If so, here we go...

http://localhost:8080/RESTfulExample -  this is the context path to your application. Tomcat can server multiple applications, so it needs the context path to differentiate them, usually it is the same as your project name.

http://localhost:8080/RESTfulExample/rest - this is the servlet path. Your application can contain multiple servlets, so the servlet path differentiates between servlets. Look at your web.xml file and down the bottom you will see how it maps the "rest" url-pattern to the servlet that implements the jersey web services.

http://localhost:8080/RESTfulExample/rest/hello - this is your resource path. The Jersey web service can represent multiple resources, so this differentiates between resources. Look at your HelloWorldService.java file and your see that there is a @Path annotation on the class that says that you can reach this resource with the path "hello"
0
 
gudii9Author Commented:
0
 
gudii9Author Commented:
projectURL/rest/hello/

http://localhost:8080/RESTfulExample/rest/hello

is project url here is

http://localhost:8080/RESTfulExample??

how it is mapping?
0
 
gudii9Author Commented:
<web-app id="WebApp_ID" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>Restful Web Application</display-name>

	<servlet>
		<servlet-name>jersey-serlvet</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>com.mkyong.rest</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>jersey-serlvet</servlet-name>
		<url-pattern>/rest/*</url-pattern>
	</servlet-mapping>

</web-app>

Open in new window

i see web.xml as above pointing rest to jersey implementation servlet

i see resource as below
package com.mkyong.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/hello")
public class HelloWorldService {

	@GET
	@Path("/{param}")
	public Response getMsg(@PathParam("param") String msg) {

		String output = "Jersey say : " + msg;

		return Response.status(200).entity(output).build();

	}

}

Open in new window

0
 
gudii9Author Commented:
i may have to keep index file when i load project on server
http://localhost:8080/RESTfulExample
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.