Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 859
Piotrek Avatar asked Oct 27 '19 19:10

Piotrek


1 Answers

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!

like image 157
Piotrek Avatar answered Oct 20 '22 22:10

Piotrek