I know there have been similar questions asked but I just started learning this in school and after following the professor's step-by-step explanation I always get an error.
I'm using Apache NetBeans 12.3 and I followed this video that was provided to us in class:
https://www.youtube.com/watch?v=zH6YYQ82V58&t=6s
My index.html looks like this:
<html>
<head>
<title>First Servlet Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<a href="FirstServlet">Click here..</a>
</body>
</html>
And the Servlet looks like this:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet FirstServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet FirstServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Most of it is code that came up automatically, all I was supposed to change was the title and the link. But when I press "Click here..." to go to the servlet I get this error:
My professor is not answering any emails and I feel very stuck as I don't have much experience with programming.