Stack Exchange
HTTP status 500 : Error instantiating servlet class [com.test.Login]
I was following a tutorial, while tring to run this little code I got this error :
HTTP status 500 : Error instantiating servlet class [com.test.Login]
Would you like please to help me to figure a solution
The Servlet :
 package com.test;

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

 public class Login extends HttpServlet {
    private static final long serialVersionUID = 1L;


public Login() {
    // TODO Auto-generated constructor stub
}


public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("Welcome !");   
}


public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
}

}
The web.xml :
//In the beggining I had an error in those two first lines just by creating a Dynamic web project before even writing anything so I copied them from a solution of the same problem on stackoverflow, I hope it's not the reason of the error now.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4">
<display-name>Test</display-name>
  <welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.html</welcome-file>
  <welcome-file>default.htm</welcome-file>
  <welcome-file>default.jsp</welcome-file>
 </welcome-file-list>
 <servlet>
 <description></description>
 <display-name>Login</display-name>
 <servlet-name>Login</servlet-name>
 <servlet-class>com.test.Login</servlet-class>
</servlet>
 <servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/login</url-pattern>
  </servlet-mapping>
</web-app>

Error I got :
javax.servlet.ServletException: Error instantiating servlet class [com.test.Login]

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
 
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
 
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
 
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
 
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:872)
 
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1695)  

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)  

org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
 
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
 
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 
java.base/java.lang.Thread.run(Thread.java:831)


Was there more in the log right after that?

Try doing away with the default constructor.

@nitind not at all

Which versions of Eclipse and Tomcat are this, because Eclipse 2021-12 M2 and Tomcat 9.0.46 are working fine for me with your files. Are there any reported Problems with your servlet's source file?

@nitind I'm working with Tomcat 9.0.54
