Search code examples
javaeclipsetomcatservletsports

Apache Tomcat 9.0 ports already in use


I know this is a common issue and I know it's plenty of suggestions to solve it. Unfortunatly non of those worked for me.

I checked with netstat -ano if the ports I need are already busy and they are taken by my only Tomcat session (as I would expect). I tried to shut tomcat down only to not being able to restart it (from task manager's service page it wont get up again, it'll keep going from arrested to running to arrested again). I tried changing the ports on Eclipse both from the server view and the server.xml with no luck. Only result I get is Tomcat to crush after a couple of switch (and not getting back online unless I reboot my laptop, as described above).

Any clue?

--EDIT--

Here's some code

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WelcomeServlet extends HttpServlet{
    // Elabora richieste "get" dai client
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

    // Spedisce pagina XHTML al client

    // Inizio documento XHTML
    out.println("<?xbl version = \"1.0\"?>");

    out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD "+"XHTML 1.0 Strict//EN\" \"http://www.w3.org"+"/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
    out.println("<html xmlns = \"http://www.w3.org/1999/xhtml\">");

    // sezione head del docuento
    out.println("<head>");
    out.println("<title>A Simple Servlet Example</title>");
    out.println("</head>");

    // sezione body del documento
    out.println("<body>");
    out.println("<h1>Welcome to Servlets!</h1>");
    out.println("</body>");

    // fine documento XTHML
    out.println("</html>");
    out.close(); //close stream to complete the page
}
}

As you can see it's a very trivial code, my very first servlet.

Down here there's the server.xml connection port:

<Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

And finally, here's Eclipse server view

enter image description here


Solution

  • Ok I managed to sort it out.

    I had to stop the apache tomcat process from the Task Manager because that was the process holding the ports. The reason it kept not working for me was that for some reason I had no index.html or similar in my project. All I had to do was to create an html page and add it to the web.xml welcome-file list.