【问题标题】:404 Not Found: Something wrong [duplicate]404 Not Found:出了点问题[重复]
【发布时间】:2017-12-23 17:40:59
【问题描述】:

我在浏览器的地址栏中输入 localhost:8080/projectName/Myservlet,得到 404 错误。

Myservlet.java

package com.test.servlet;  

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Myservlet extends HttpServlet{
    public void doGet(HttpServletRequest request,
        HttpServletResponse response) throws IOException{
        PrintWriter out=response.getWriter();

        out.println("<html><body><h1>Today</h1>Myservlet</body></html>");
    }
}

web.xml

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

    <Servlet-mapping>
        <Servlet-name>servlet</Servlet-name>
        <url-pattern>/Myservlet</url-pattern>
    </Servlet-mapping>
</web-app>

【问题讨论】:

  • 如果您之前设置了本地服务器,您可能在端口 8081 上运行。确保您验证了这一点——但对于 GP,它是什么类型的服务器?你在用球衣吗?给我们更多信息

标签: jsp servlets http-status-code-404


【解决方案1】:

在 web.xml 中你没有定义类的完整路径:

<Servlet>
    <Servlet-name>servlet</Servlet-name>
    <Servlet-class>com.test.servlet.Myservlet</Servlet-class>
</Servlet>

<Servlet-mapping>
    <Servlet-name>servlet</Servlet-name>
    <url-pattern>/Myservlet</url-pattern>
</Servlet-mapping>

com.test.servlet 是 Myservlet 类的包名。请使用类的完整路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 2018-01-04
    • 2011-02-20
    • 1970-01-01
    • 2016-10-26
    • 2015-05-10
    • 2017-09-30
    相关资源
    最近更新 更多