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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With