1

I've been stuck with this problem the whole morning and I can't seem to understand why.

This is my servlet. Very simple:

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class hello
 */
@WebServlet("/hello")
public class hello extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public hello() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().write("test");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

When I start my tomcat server, and go to http://localhost:8080/testh/hello I receive the error message: HTTP Status 404 - /testh/hello

Why? The server is started, and I have this specific servlet /hello running under the project "testh". I don't understand. Please help.

John Solve
  • 11
  • 1
  • 1
    please share your web.xml – sAm Sep 15 '16 at 08:44
  • Check your deployment assembly if everything is deploying correctly, server class should be in `webapps/testh/WEB-INF/classes/hello.class` in tomcat. Also, name your classes staring with big letter like `Hello`. – Shadov Sep 15 '16 at 08:50
  • It often helps enormously to read error messages carefully (see also the server logs). – Henry Sep 15 '16 at 09:24

1 Answers1

0

Try to call http://localhost:8080/hello

Because all you project is under the root

/

And then you have mapping /hello

Also if you need exactly http://localhost:8080/testh/hello you should deploy app using path /testh and then HTTP call will route you to /testh/hello because your servlet path is /hello + app path /testh

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • His project name is `testh` and it needs to be included in a path, so just `http://localhost:8080/hello` shouldn't work. – Shadov Sep 15 '16 at 08:51