【问题标题】:Error 404 when trying to access my Servlet尝试访问我的 Servlet 时出现错误 404
【发布时间】:2017-04-25 17:42:32
【问题描述】:


我正在使用 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.
尝试访问地址时,控制台中也没有出现任何消​​息,但我不确定它应该。

【问题讨论】:

    标签: java servlets servlet-3.0


    【解决方案1】:

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

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

    【讨论】:

    • 我听说 web.xml 从 Servlet 3.0 开始就不需要了。
    猜你喜欢
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    相关资源
    最近更新 更多