gpt4 book ai didi

java - servlet 程序 HTTP Status 404 -/HelloWorldServlet/时出现错误

转载 作者:行者123 更新时间:2023-12-01 13:51:04 24 4
gpt4 key购买 nike

我的 Servlet 程序

包 com.srccodes.example;

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 Helloworld
*/
@WebServlet("/Helloworld")
public class Helloworld extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Helloworld() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter printWriter = response.getWriter();
printWriter.println("<h1>Hello World!</h1>");
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

更新:

wec.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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
<display-name>HelloWorldServlet</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

在 tomcat 服务器上运行上述程序时出现错误错误 --> /image/655Ew.png 。如何解决这个问题,请尝试建议我,好的答案将不胜感激

最佳答案

您上面提供的代码没有任何问题。您的 servlet 名称是“Helloworld”,您尝试的 URL 是

http://localhost:8080/HelloworldServlet

如果您想运行相同的 servlet,请尝试

http://localhost:8080/HelloworldServlet/Helloworld

同时重新启动服务器并检查 URL。

关于java - servlet 程序 HTTP Status 404 -/HelloWorldServlet/时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19947889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com