尝试访问我的Servlet时出错404

时间:2017-04-25 17:42:33

标签: java servlets servlet-3.0


我正在使用Java和Servlet创建一个简单的Web应用程序,但我似乎无法访问应该可用的地址:http://localhost:8080/Financeiro/oi-mundo
这是我的Servlet:

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
  * Servlet implementation class OiMundoServlet
*/
@WebServlet("/oi-mundo")
public class OiMundoServlet extends HttpServlet {
     private static final long serialVersionUID = 1L;

     /**
       * @see HttpServlet#doGet(HttpServletRequest request, 
     HttpServletResponse response)
     */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
         PrintWriter out = response.getWriter();
         System.out.println("Ola mamae");
         out.print("<html>");
         out.print("<body><h1>Oi Mundo</h1></body>");
         out.print("</html>");
         out.flush();
     }

 }

这是pom.xml:

 <project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.algaworks</groupId>
  <artifactId>Financeiro</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>

            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>

</project>


项目和控制台中没有错误,只有警告:
[SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Financeiro' did not find a matching property
尝试访问地址时,控制台中也不会显示任何消息,但我不确定是否应该这样做。

1 个答案:

答案 0 :(得分:0)

web.xml配置问题。请检查您的web.xml配置。你可以按照下面提到的链接: -

https://www.intertech.com/Blog/servlet-3-0-how-to-override-webservlet-mappings/