【问题标题】:WebServlet with 404 Error using Maven3 Eclipse 7 Tomcat 7使用 Maven3 Eclipse 7 Tomcat 7 出现 404 错误的 WebServlet
【发布时间】:2012-08-08 10:41:32
【问题描述】:

我的项目名为“A”,我的班级是:

@WebServlet(urlPatterns={"/test/*"}) public class RequestHandler extends HttpServlet {

Maven 插件:

<plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      </plugin>

在 src/main/webapp/WEB-INF/web.xml 我有

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"/>

Tomcat7在运行tomcat7时是这样启动的:运行:

Running war on http://localhost:8080/A

...

2012 年 8 月 8 日下午 12:28:08 org.apache.coyote.AbstractProtocol 初始化 信息:初始化 ProtocolHandler ["http-bio-8080"] 2012 年 8 月 8 日 12:28:08 PM org.apache.catalina.core.StandardService startInternal 信息:启动服务Tomcat 2012 年 8 月 8 日下午 12:28:08 org.apache.catalina.core.StandardEngine startInternal 信息:启动 Servlet 引擎:Apache Tomcat/7.0.25 2012 年 8 月 8 日下午 12:28:08 org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment 信息:未找到全局 web.xml 2012 年 8 月 8 日 12:28:09 PM org.apache.coyote.AbstractProtocol 开始 信息:启动 ProtocolHandler ["http-bio-8080"]

当我转到 http://localhost:8080/Ahttp://localhost:8080/A/test 时,我从 Tomcat7 得到一个 404

我做错了什么?

【问题讨论】:

    标签: tomcat maven servlets tomcat7


    【解决方案1】:

    删除 web.xml 文件。

    配置你的 pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.0-SNAPSHOT</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8080</port>
                    <path>/</path>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-core</artifactId>
                        <version>7.0.29</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>apache.snapshots</id>
            <name>Apache Snapshots</name>
            <url>http://repository.apache.org/content/groups/snapshots-group/</url>
        </pluginRepository>
    </pluginRepositories>
    

    【讨论】:

      猜你喜欢
      • 2017-02-13
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      相关资源
      最近更新 更多