Skip to content

Tomcat 404 – Not Found: when Implementing REST API

I’m trying to implement simple RESTFUL API service using dynamic web application in Eclipse. Every time I am getting error message HTTP Status 404 – Not Found.

I have attached my screen below

Package structure

My RestFul API Code Picture

I am able to run tomcat server on localhost:8080 as shown on the above figure but when I trying to access my api path I am getting 404 not found error

Here is my whole code



public class ScoreService {
    private static int wins ,losses, ties;

    public String getScore() {
       String pattern = 
          "{ "wins":"%s", "losses":"%s", "ties": "%s"}";
       return String.format(pattern,  wins, losses, ties );   
    public String updateScore( @QueryParam("wins")int wins,
                                @QueryParam("losses")int losses,
                                @QueryParam("ties")int ties) {
        ScoreService.wins = wins;
        ScoreService.losses = losses;
        ScoreService.ties = ties;
        String pattern = 
                  "{ "wins":"%s", "losses":"%s", "ties": "%s"}";
              return String.format(pattern,  wins, losses, ties );   


    @POST @Path("/score/wins") @Produces("text/plain")
    public int increaseWins() {
        return ++wins;
    @POST @Path("/score/ties") @Produces("text/plain")
    public int increaseTies() {
        return ++ties;
    @POST @Path("/score/losses") @Produces("text/plain")
    public int increaseLosses() {
        return ++losses;

    @GET @Path("/score/wins") @Produces("text/plain")
    public int getWins() {
        return wins;

    @GET @Path("/score/losses") @Produces("text/plain")
    public int getLosses() {
        return losses;

    @GET @Path("/score/ties") @Produces("text/plain")
    public int getTies() {
        return ties;

Inside Webcontent I have web.xml and I have following code here:

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xsi:schemaLocation="" id="WebApp_ID" version="3.1">



You have missed the mapping in your web.xml. Add the following lines :

    <servlet-name>My Servlet</servlet-name>
    <servlet-name>My Servlet</servlet-name>

Basically what this configuration is doing is mapping urls with pattern /api/* to a servlet which is required.

Also looks like you are using jersey for your REST implementation. Now you can try to access your api’s using the following url:


User contributions licensed under: CC BY-SA
6 People found this is helpful