Home>

I recently started learning java.
I'm writing java code using eclipse on mac, but when I try to start tomcat, I get an error and can't start it. Why is it an error?
I also checked the error code, but I don't understand the cause.

As for the code, I'm going to save what I type in the form to the database.
I wanted to share the part that accesses the database with multiple classes, so I separated it as a parent class.

Severe: An exception was thrown in the Begin event. [Mon November 16 20:01:11 JST 2020]
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    at java.base/java.lang.ClassLoader.defineClass1 (Native Method)
    at java.base/java.lang.ClassLoader.defineClass (ClassLoader.java: 1016)
    at java.base/java.security.SecureClassLoader.defineClass (SecureClassLoader.java:151)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass (BuiltinClassLoader.java:825)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull (BuiltinClassLoader.java:723)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull (BuiltinClassLoader.java:646)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:604)
    at java.base/jdk.internal.loader.ClassLoaders $AppClassLoader.loadClass (ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass (ClassLoader.java:522)
    at java.base/java.lang.Class.getDeclaredMethods0 (Native Method)
    at java.base/java.lang.Class.privateGetDeclaredMethods (Class.java:3325)
    at java.base/java.lang.Class.privateGetPublicMethods (Class.java:3350)
    at java.base/java.lang.Class.getMethods (Class.java:1996)
    at org.apache.tomcat.util.IntrospectionUtils.findMethods (IntrospectionUtils.java:406)
    at org.apache.tomcat.util.IntrospectionUtils.setProperty (IntrospectionUtils.java:70)
    at org.apache.tomcat.util.digester.SetPropertiesRule.begin (SetPropertiesRule.java:104)
    at org.apache.tomcat.util.digester.Digester.startElement (Digester.java:1293)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement (AbstractSAXParser.java:518)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement (AbstractXMLDocumentParser.java:183)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement (XMLDocumentFragmentScannerImpl.java: 1386)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl $FragmentContentDriver.next (XMLDocumentFragmentScannerImpl.java:2725)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next (XMLDocumentScannerImpl.java:605)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument (XMLDocumentFragmentScannerImpl.java:541)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (XML11Configuration.java:888)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (XML11Configuration.java:824)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse (XMLParser.java:141)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse (AbstractSAXParser.java:1224)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl $JAXPAXParser.parse (SAXParserImpl.java:635)
    at org.apache.tomcat.util.digester.Digester.parse (Digester.java:1551)
    at org.apache.catalina.startup.Catalina.parseServerXml (Catalina.java:617)
    at org.apache.catalina.startup.Catalina.load (Catalina.java:709)
    at org.apache.catalina.startup.Catalina.load (Catalina.java:746)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke (Method.java:564)
    at org.apache.catalina.startup.Bootstrap.load (Bootstrap.java:302)
    at org.apache.catalina.startup.Bootstrap.main (Bootstrap.java:472)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:606)at java.base/jdk.internal.loader.ClassLoaders $AppClassLoader.loadClass (ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass (ClassLoader.java:522)
    ... 38 more
Corresponding source code
<% @ page language = "java" contentType = "text/html;charset = UTF-8"
    pageEncoding = "UTF-8"%><! DOCTYPE html><html><head><meta charset = "UTF-8"><title>Insert title here</title><link rel = "stylesheet" href = "lib/style.css"></head><body><form action = "database/InsertCustomer" method = "POST"><table><tr><th align = "right">Name:</th><td><input type = "text" name = "name" size = 35 maxlength = "20"></td></tr><tr><th align = "right">email address:</th><td><input type = "text" name = "email" size = 35 maxlength = "50"></td></tr><tr><th align = "right">Password:</th><td><input type = "password" name = "password" size = 35 minlength = "8" maxlength = "15"></td></tr><tr><th align = "right">Address:</th><td><input type = "text" name = "adress" size = 35 maxlength = "20"></td></tr><tr><th align = "right">Phone number:</th><td><input type = "tel" name = "tel" size = 35 maxlength = "10"></td></tr><tr><td colspan = "2"><input type = "submit" value = "register"></td></table></form></body></html>
package database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
/ *** Servlet implementation class BaseServlet
 * /
@WebServlet ("/ database/BaseServlet")
public class BaseServlet extends HttpServlet {
    public Connection getConnection () {
        Connection con = null;
        String url = "jdbc: mariadb: // localhost: 3306/customer";
        String user = "root";
        String pass = "root";
        try {
            con = DriverManager.getConnection (user, pass, url);
        } catch (SQLException e) {
            e.printStackTrace ();
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return con;
    }
}
package database;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/ **
 * Servlet implementation class InsertCustomer
 * /
@WebServlet ("/ database/InsertCustomer")
public class InsertCustomer extends BaseServlet {
   /**
     * @see HttpServlet # doPost (HttpServletRequest request, HttpServletResponse response)
     * /
    protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PreparedStatement statement = null;
        Connection con = null;
        String sql = "INSERT INTO customer (name, email, password, adress, tel) VALUES (?,?,?,?,?)";
        try {
            con = super.getConnection ();
            statement = con.prepareStatement (sql);
            statement.setString (1, request.getParameter ("name"));
            statement.setString (2, request.getParameter ("email"));
            statement.setString (3, request.getParameter ("password"));
            statement.setString (4, request.getParameter ("adress"));statement.setString (5, request.getParameter ("tel"));
            statement.executeUpdate ();
        } catch (SQLException e) {
            e.printStackTrace ();
        } catch (Exception e) {
            e.printStackTrace ();
        } finally {
            try {
                if (statement! = null) {con.close ();}
                if (con! = null) {con.close ();}
            } catch (Exception e) {
                e.printStackTrace ();
            }
        }
    }
}
<? xml version = "1.0" encoding = "UTF-8"?><web-app xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://xmlns.jcp.org/xml/ns/javaee" xsi: schemaLocation = "http" //xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version = "4.0"><display-name>shopinf</display-name><welcome-file-list><welcome-file>entryCustomer.jsp</welcome-file><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file></welcome-file-list><servlet><servlet-name>BassServlet</servlet-name><servlet-class>database.BaseServlet</servlet-class></servlet><servlet-mapping><servlet-name>BassServlet</servlet-name><url-pattern>/database/BaseServlet</url-pattern></servlet-mapping><servlet><servlet-name>InsertCustomer</servlet-name><servlet-class>database.InsertCustomer</servlet-class></servlet><servlet-mapping><servlet-name>InsertCustomer</servlet-name><url-pattern>/database/InsertCustomer</url-pattern></servlet-mapping></web-app>
What I tried

Check java version, restart and reconfigure tomcat.

Supplementary information (FW/tool version, etc.)

The tomcat version is 9.0 and the java version is 15.
eclipse uses the Full Edition of pleiades.