I am trying to make my first web application with java servlet, apache tomcat and java. This are my directories
This is my java file saved as HelloServlet.java
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
public class HelloServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out = response.getWriter();
out.println("<html>\n\t<head>\n\t\t<title>Hello!</title>\n\t</head>");
out.println("\t<body>\n\t\tHello, world.\n\t</body>");
}
}
The java file compiled just fine no problem there.
This is my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/Web-app_2_3.dtd">
<web-app>
<display-name>The Hello World Application</display-name>
<description>Prints hello world!</description>
<servlet>
<servlet-name>hello</servlet-name>
<description>This is a simple Servlet</description>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</Web-app>
Apache Tomcat is successfully installed and running just fine I changed the port number to 8888 which was also just fine.
but if I visit http://localhost:8888/hello I get a directory list of the folder hello instead of a simple web page with Hello, world. Why so?