【问题标题】:Servlet Mapping Tomcat Error EclipseServlet 映射 Tomcat 错误 Eclipse
【发布时间】:2016-10-28 13:17:21
【问题描述】:

我正在尝试在 Eclipse 中进行 servlet 映射。使用注释来映射 servlet 似乎工作正常,但是当我尝试使用 web.xml 文件时,我遇到了问题。我也希望能够映射 jsp,因此我想在注释样式上使用 xml 文件。这是我在尝试将 servlet 映射添加到 web.xml 文件时遇到的错误。

'Starting Tomcat v8.0 Server at localhost'遇到了问题。 Server Tomcat v8.0 Server at localhost 启动失败。

这是我的 web.xml 文件:

<?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_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>Ryans Testing Project</display-name>
    <welcome-file-list>
        <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>default.jsp</welcome-file>
    </welcome-file-list>
    
    <servlet>
        <servlet-name>AController</servlet-name>
        <servlet-class>controller/AController</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AController</servlet-name>
        <url-pattern>/AController</url-pattern>
    </servlet-mapping>


</web-app>

另外,这是我的文件结构的图像:

【问题讨论】:

  • 下次您看到此一般性错误消息时遇到问题,只需查看服务器日志以获取详细答案。很有可能这是一个(相当不言自明的)java.lang.ClassNotFoundException: controller/AController

标签: java eclipse tomcat servlets mapping


【解决方案1】:

&lt;servlet-class&gt; 标记只能采用完全限定的类名。所以这样做

<servlet>
    <servlet-name>AController</servlet-name>
    <servlet-class>controller.AController</servlet-class>
</servlet>

controller 是包名。

我也希望能够映射 jsp,因此我想使用 xml 文件而不是注释样式。

这是 Servlet 3.0 规范所说的:

10.13 Inclusion of a web.xml Deployment Descriptor

如果 Web 应用程序不包含任何 Servlet、Filter 或 Listener 组件或使用注释来声明它们,则不需要包含 web.xml。换句话说,仅包含静态文件或 JSP 页面的应用程序不需要存在 web.xml。

【讨论】:

    猜你喜欢
    • 2012-07-18
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多