Error initializing servlet class

Asked 2 years ago, Updated 2 years ago, 90 views

I'm a beginner in programming.While I was learning Servlet on my own, I suddenly got an error in the Servlet file, so I would like to post it.

Environment:
Windows 10 Use vscode
Tomcat 10.0
jdk-17.0.1

There are only jsp files to send to PokemonServlet as follows:

<%@pagecontentType="text/html;charset=UTF-8"%>
<!DOCTYPE html>
<html lang="ja">
<head>
    <metacharset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> Pokemon Damage Calculator</title>
</head>
<body>
<form method="POST" action="PokemonServlet">

    <p><input type="submit" value="send">/p>
    <input type="reset" value="Cancel">

</form>

</body>
</html>

The following is the PokemonServlet.java file.

package to.msn.wings.selfjsp;
import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import jakarta.servlet.announcement.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


@ WebServlet ("/PokemonServlet")
public class PokmonServlet extensions HttpServlet {
    @Override
    protected void doPost (HttpServletRequest request, HttpServletResponse response) 
    US>throws ServletException, IOException {

        response.setContentType("text/html; charset=UTF-8";
        PrintWriter out=response.getWriter();        
        out.println("<!DOCTYPE html><html>head><metacharset='UTF-8'>");
        out.println("<title>Scriptlet</title>");
        out.println("</head><body>");
        for(inti=0;i<5;i++){
        out.println("Hello, world!<br>");
        }
        out.println("</body></html>");      

     }

    
}

The following error occurs when you press the Send button from a jsp file:

jakarta.servlet.ServletException: Error initializing servlet class [to.msn.wings.selfjsp.PokemonServlet]
    org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:541)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve.java:690)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process (AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process (AbstractProtocol.java:872)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun (NioEndpoint.java:1705)
    org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor $Worker.run (ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingR

java.lang.UnsupportedClassVersionError: Cannot load Preview features are not enabled for to/msn/wings/selfjsp/PokemonServlet (class file version 61.65535).Try running with '--enable-preview'
    org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal (WebappClassLoaderBase.java:2521)
    org.apache.catalina.loader.WebappClassLoaderBase.findClass (WebappClassLoaderBase.java:872)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java:1408)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java:1252)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:541)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve.java:690)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process (AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process (AbstractProtocol.java:872)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun (NioEndpoint.java:1705)
    org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor $Worker.run (ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run (Thread.java:833)

When I checked Tomcat's log, I didn't know how it was related to the above error, but I found that the following error occurred.

org.apache.catalina.util.LifecycleBase.handleSubClassException component [Connector [HTTP/1.1-8080]] failed to initialize.
    org.apache.catalina.LifecycleException - Protocol handler initialization failed
        at org.apache.catalina.connector.Connector.initInternal (Connector.java: 1055)
        at org.apache.catalina.util.LifecycleBase.init (LifecycleBase.java:136)
        at org.apache.catalina.core.StandardService.initInternal (StandardService.java:556)
        at org.apache.catalina.util.LifecycleBase.init (LifecycleBase.java:136)
        at org.apache.catalina.core.StandardServer.initInternal (StandardServer.java:1042)
        at org.apache.catalina.util.LifecycleBase.init (LifecycleBase.java:136)
        at org.apache.catalina.startup.Catalina.load (Catalina.java:747)
        at org.apache.catalina.startup.Catalina.load (Catalina.java:769)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke (Method.java:568)
        at org.apache.catalina.startup.Bootstrap.load (Bootstrap.java:305)
        at org.apache.catalina.startup.Bootstrap.main (Bootstrap.java:475)
    Caused by:java.net.BindException:Address already in use:bind
        at java.base/sun.nio.ch.Net.bind0 (Native Method)
        at java.base/sun.nio.ch.Net.bind (Net.java:555)
        at java.base /sun.nio.ch.ServerSocketChannelImpl.netBind (ServerSocketChannelImpl.java:337)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind (ServerSocketChannelImpl.java:294)
        at org.apache.tomcat.util.net.NioEndpoint.initServerSocket (NioEndpoint.java:244)
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:199)
        at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup (AbstractEndpoint.java:1184)
        at org.apache.tomcat.util.net.AbstractEndpoint.init (AbstractEndpoint.java:1197)
        at org.apache.coyote.AbstractProtocol.init (AbstractProtocol.java:580)
        at org.apache.coyote.http11.AbstractHttp11Protocol.init (AbstractHttp11Protocol.java:82)
        at org.apache.catalina.connector.Connector.initInternal (Connector.java:1052)

I don't know exactly how to correct it.I'm sorry that the information is fragmentary, but if you know anything, please let me know.

java jsp servlet

2022-09-30 11:13

1 Answers

An exception that occurs when a compilation with the --enable-preview option is performed without the --enable-preview option.

I don't think preview functionality is required this time, so removing --enable-preview from the compilation option should solve the problem.

The configured file depends on which project configuration tool you are using (how you are building .war), but if you are using Maven, Gradle, you should remove it and run Java: Clean Java Language Server Workspace from the command palette.

(There is no information about this area in the questionnaire, so if neither Maven nor Gradle are using it, please add it to the questionnaire how you are building it.)

Conversely, if you want to enable and run the preview function, you can also give the JVM option at Tomcat startup with --enable-preview (remain the above settings).
If you are using the Tomcat for Java enhancement, right-click >Customize JVM Options in the "TOMCAT SERVERS" panel and click

in the displayed configuration file.
 --enable-preview

It seems to be possible by adding .

The exception mentioned in the second half is a different issue because you tried to boot the server using the port you are using (probably trying to double boot).


2022-09-30 11:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.