Billy
Billy

Reputation: 193

Tomcat 9.027: port out of range

I have a problem with connect my servlet with Tomcat v9.0.27. When I try start my servlet in IntelliJ, Tomcat give me this error:

Error running 'Tomcat 9.0.27': port out of range:-1

My port is 8080, I try to change port but this not help me Windows 10, x64

My configuration from IntellJ: https://zapodaj.net/3eab70769b2ef.png.html

My code:

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

@WebServlet("/hello")
public class hello extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        PrintWriter writer = response.getWriter();
        writer.println("HelloWorld");
    }
}

Anybody have any solution to this problem?

Upvotes: 5

Views: 16097

Answers (1)

Billy
Billy

Reputation: 193

I have a solution, we need to go to the configuration files of our Tomcat:

C:/Program Files/Apache Software Foundation/Tomcat/conf

We must edit our server.xml.

In line:

Server port="-1" shutdown="SHUTDOWN"

you must change "-1" to something else but greater than zero, for example:

Server port="1" shutdown="SHUTDOWN"

Then only save all changes, and restart your project.

Have a nice day!

Upvotes: 8

Related Questions