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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.