使用@WebServlet注解启动Tomcat Servlet的问题

问题描述 投票:0回答:1

早上好。

我的 servlet 启动有问题。请你帮助我好吗? 我正在使用

  • Tomcat 9.0.82
  • 科雷托 11.0.17.8.1
  • Windows 10 19045.3570

我有一个已编译的 WAR 存档,其目录结构如下。

   WAR
     - index.htm
     - img
       - some_images.gif
     - WEB-INF
       - web.xml
     - lib/my.jar
       - servlet.HelpServlet.class`

web.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?\>

<!-- Metadata-complete Attribute: If your web.xml contains the attribute 
  metadata-complete="true" in the  tag, this will instruct the server 
  to ignore annotations and use only the web.xml for deployment configuration. -->

<web-app xmlns="http://java.sun.com/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"
version="3.1" metadata-complete="false"\>

  <mime-mapping>
    <extension>wsdl</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>
  
  <mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>

servlet 具有以下定义:

@WebServlet(
name = "HelpServlet",
urlPatterns = "/help/\*")
public class HelpServlet extends javax.servlet.http.HttpServlet
{
private static final long serialVersionUID = -2877995723829943551L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("HELP PLEASE");
    }

}

我的 tomcat 有以下配置(从 vanilla 更改):

  • conf/server.xml 将端口从 8080 更改为 6080

    <Host name="localhost"  appBase="../webapp/app" unpackWARs="true"\> 

  • conf/Catalina/localhost/app.xml

  <?xml version="1.0" encoding="ISO-8859-15"?>
  <Context docBase="D:/app-deploy/webapp/app.war" reloadable="false" />

是否有任何我忘记配置的 servlet 在服务器启动时启动? war 存档将部署在预期目录中。在浏览器中可以找到并查看index.htm,但是找不到localhost:8080/app/help下的HELP-Servlet 404!

这是完整的日志文件:

[09:34:41] <Guest28> 14-Nov-2023 09:29:50.270 INFORMATION [main] org.apache.coyote.AbstractProtocol.init Initialisiere ProtocolHandler["http-nio-6080"]
[09:34:41] <Guest28> 14-Nov-2023 09:29:50.319 INFORMATION [main] org.apache.catalina.startup.Catalina.load Server initialization in [1059] milliseconds
[09:34:41] <Guest28> 14-Nov-2023 09:29:50.446 INFORMATION [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
[09:34:41] <Guest28> 14-Nov-2023 09:29:50.447 INFORMATION [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.82]
[09:34:41] <Guest28> 14-Nov-2023 09:29:50.468 INFORMATION [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [D:\java-ide\workspace\webframe-deploy\apache-tomcat-9.0.82\conf\Catalina\localhost\webframe.xml]
[09:34:41] <Guest28> 14-Nov-2023 09:30:30.455 INFORMATION [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[09:34:41] <Guest28> 14-Nov-2023 09:33:54.540 WARNUNG [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [260] milliseconds.
[09:34:41] <Guest28> 14-Nov-2023 09:33:54.635 INFORMATION [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [D:\java-ide\workspace\webframe-deploy\apache-tomcat-9.0.82\conf\Catalina\localhost\webframe.xml] has finished in [244.166] ms
[09:34:41] <Guest28> 14-Nov-2023 09:33:54.638 INFORMATION [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-6080"]
[09:34:41] <Guest28> 14-Nov-2023 09:33:54.920 INFORMATION [main] org.apache.catalina.startup.Catalina.start Server startup in [244596] milliseconds

预计 Tomcat 将在 [GET] http://localhost:6080/app/help 下启动定义的 servlet 但目前情况并非如此。 🤔

怎么了?请帮忙。 提前致谢。 克里斯蒂安

java servlets startup tomcat9
1个回答
0
投票

我一直在寻找的问题🙈:

2023 年 11 月 14 日 10:56:08.673 SCHWERWIEGEND [main] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [HelpServlet] 在 Web 应用程序 [/app] 中引发了 load() 异常 java.lang.UnsupportedClassVersionError: servlet/HelpServlet 已由较新版本的 Java 运行时(类文件版本 60.0)编译,此版本的 Java 运行时仅识别最高版本为 55.0 的类文件(无法加载类 [servlets.java])。帮助Servlet]) 在org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2484)

注意! 不要使用 buildIn JRE 16 在 Eclipse 中通过 ANT 进行编译,并使用 JRE 11 在 Tomcat 上部署。😣

© www.soinside.com 2019 - 2024. All rights reserved.