I was executing a web project and it is throwing an error 500 error instatiating servlet class . I am using tomcat 9.0.71 and using web module 4.0 .
This is the error message on the screen.
This is the HTML document
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>This is a hello world</h1>
<br>
<form action ="hello" method="get">
<input type="submit">click to say hello world
</form>
</body>
</html>
This is the servlet class
package ronit;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.*;
@WebServlet("/hello")
class hello extends HttpServlet{
static final long serialVersionUID = 35335L;
public void doGet(HttpServletRequest req, HttpServletResponse res) {
try {
PrintWriter p = res.getWriter();
p.println("Hello World");
}catch(IOException e) {e.printStackTrace();}
}}
This is the deployment configuration in the server
This is the console after execution
This is the project explorer view
I am using annotations instead of web.xml and deploying the file by right clicking on the project and run on server.
Your servlet class has no public, zero argument, constructor. It needs one, otherwise Tomcat can not instantiate it--exactly as the error output is telling you.