Restful Webservice HelloWorld Example Jersey 1.x

This tutorial covers how to create Restful webservice (JAX-RS) using Jersey 1.x version. Jersey released version 2 already, in upcoming tutorials we will see webservice examples using Jersey 2.

Create maven web application project and add Jersey dependency in pom.xml. Find Jersey 1.x maven dependency configuration below. If you are new to maven refer our maven tutorials.

Jersey dependency in pom.xml

<project xmlns="" xmlns:xsi=""
  <name>RestTutorials Maven Webapp</name>

Configure Jersey Servlet dispatcher

We need to configure Jersey ServletContainer as servlet in our web.xml and our rest class package in init param. Find the sample web.xml below “com.ehowtonow.webservice” is the package where we are going to create our Rest java classes.

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

	<display-name>Restful Webservice Example</display-name>


This is servlet class available in jersey com.sun.jersey.spi.container.servlet.ServletContainer. The init param is used to defines in which package jersey will look for the web service classes. This package point to your resource class package. URL pattern is part of your base URL

package com.ehowtonow.webservice;


public class RestHelloWorld {
 public String sayHello(){
  return "Welcome to";
 public Response greetUser(@PathParam("userName") String userName)
     String output = "Welcome  : " + userName;
     return Response.status(200).entity(output).build();


This class called by using base url + path and get resource using HTTP GET method its is specified by annotation @GET and it produce the Sting output as Plain Text output and @PATH define the URI to access rest service.

You can see there are different JAX-RS annotation in both the methods. We will see each and every JAX-RS annotations in details with example program.

You can access both rest apis using below url. http://localhost:8080/RestTutorials/rest/hello http://localhost:8080/RestTutorials/rest/hello/Annamalai See the output below.

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. JAX-RS Get HTTP Headers using @HeaderParam
  2. RESTful Web service to consume JSON and Produce XML – Jersey 1.x
  3. Download Excel file using JAX-RS RESTful Webservice
  4. JAX-RS @PathParm Web service Example
  5. JAX-RS Web service to Consume JSON using Jersey 1.x
  6. JAX-RS Web Service to produce XML using JAXB
  7. Restful Webservice HelloWorld Example Jersey 1.x
  8. JAX-RS Send List using QueryParam Annotation
  9. JAX-RS @MatrixParam Restful Webservice
  10. JAX-RS @QueryParam with @DefaultValue – Jersey
  11. Download image using JAX-RS RESTful Webservice
  12. Download Text file using JAX-RS RESTful Webservice
  13. JAX-RS @FormParam Web service example
  14. JAX-RS Get HTTP Headers using @Context
  15. File Upload using JAX-RS RESTful Webservice (Jersey 2.x)

Be the first to comment

Leave a Reply