0

I'm new to NetBeans and JSP Servlet and I'm trying to create a Web Application using JSP Servlet in Apache NetBeans 11.1 and I keep getting this error:

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Error instantiating servlet class [controller.NewServlet]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception  
javax.servlet.ServletException: Error instantiating servlet class [controller.NewServlet]
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)

I tried uninstalling Netbeans and Tomcat server and reinstall them but still, got the same error.

This is what my Web.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <servlet>
        <servlet-name>NewServlet</servlet-name>
        <servlet-class>controller.NewServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>NewServlet</servlet-name>
        <url-pattern>/NewServlet</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

My servlet

package controller;

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;

/**
 *
 * @author sagarluitel
 */
public class NewServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    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 NewServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Sign up here</h1>

        <form action="NewServlet" method="post" onsubmit="return validateForm();">

            <input type="hidden" name="action" value="signup">

            <label>First Name</label>
            <input type="text" id="firstName" name="firstName" placeholder="First Name" required><br>

            <label>Last Name</label>
            <input type="text" id="lastName" name="lastName" placeholder="Last Name" required><br>

            <label>Email</label>
            <input type="email" id="email" name="email" placeholder="Email" required><br>

            <label>Password</label>
            <input type="password" id="password" name="password" placeholder="Password" required><br>
            <i>Use 8 or more characters with a mix of letters, numbers & symbols</i><br>

            <input type="submit" value="Submit"><br>
        </form>
    </body>
</html>

File path:

WebApplication
    Web Pages
        META-INF
        WEB-INF
            web.xml
        index.jsp
    Source Packages 
        controller
            NewServlet.java    

My problem is not same as this (HTTP Status 500 - Error instantiating servlet class pkg.coreServlet) because My src folder is not in the WEB-INF directory.

Can someone please help me with this, I don't know what am I missing or doing wrong. I'm using macOS Catalina, got the same error while using the previous version of Mac as well.

5a9ar
  • 1
  • 2
  • Does this answer your question? [HTTP Status 500 - Error instantiating servlet class pkg.coreServlet](https://stackoverflow.com/questions/15921540/http-status-500-error-instantiating-servlet-class-pkg-coreservlet) – Lakshan Nov 03 '19 at 18:31
  • No, I already check that out and I don't think that the problem. – 5a9ar Nov 03 '19 at 19:28

0 Answers0