2012-08-08 49 views
0

我的項目被命名爲 「A」 和我的課是:WebServlet使用Maven3 Eclipse的7 Tomcat的404錯誤7

@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秒org.apache.catalina.core.StandardService startInternal 信息:啓動服務Tomcat Aug 08,2012 12:28:08 PM org .apache.catalina.core.StandardEngine startInternal Inf ormation:啓動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分:下午9點開始org.apache.coyote.AbstractProtocol信息 :啓動ProtocolHandler [ 「HTTP-BIO-8080」]

當我去http://localhost:8080/Ahttp://localhost:8080/A/test我從Tomcat7

什麼時得到一個404我做錯了?

回答

0

刪除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> 
相關問題