Я новичок в NetBeans и JSP Servlet, и я пытаюсь создать веб-приложение с использованием JSP Servlet в Apache NetBeans 11.1, и у меня постоянно появляется эта ошибка:
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)
Я пытался удалить Netbeans иСервер Tomcat и переустановить их, но все же, получил ту же ошибку.
Вот так выглядит мой Web.xml:
<?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>
Мой сервлет
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>
Путь к файлу:
WebApplication
Web Pages
META-INF
WEB-INF
web.xml
index.jsp
Source Packages
controller
NewServlet.java
Моя проблема не такая ( HTTP Status 500 - Ошибка при создании экземпляра класса сервлета pkg.coreServlet ), поскольку моя папка src не находится в каталоге WEB-INF.
Может кто-нибудь, пожалуйста, помогите мне с этим, я не знаю, что я пропускаю или делаю неправильно. Я использую macOS Catalina, также получаю ту же ошибку при использовании предыдущей версии Mac.