gpt4 book ai didi

java - tomcat请求的资源()不可用

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:09:50 24 4
gpt4 key购买 nike

<分区>

我知道这是一个非常常见的问题,因为我在几个论坛(包括 SO)中发现了很多与此相关的问题。但我还没有找到解决办法我的 web.xml(位于 WEB-INF 中)

<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SMSProjectNew</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>ReceiveMessagesServlet</display-name>
<servlet-name>ReceiveMessagesServlet</servlet-name>
<servlet-class>com.sendreceive.ReceiveMessagesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReceiveMessagesServlet</servlet-name>
<url-pattern>/ReceiveMessagesServlet</url-pattern>
</servlet-mapping>
</web-app>

html 页面 index.html,位于 WebContent 文件夹中

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
The application started successfully version 1:27
<form action="/ReceiveMessagesServlet" method="post">
<input type="text" name="number"/>
<input type="text" name="message"/>
<input type="submit" name="submit"/>
</form>
</body>
</html>

最后是 servlet,ReceiveMessagesServlet,位于 src\com.sendreceive包 com.sendreceive;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReceiveMessagesServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public ReceiveMessagesServlet() {
super();
// TODO Auto-generated constructor stub
}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request,response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request,response);
}

protected void processRequest(HttpServletRequest request,
HttpServletResponse response) {
String responseMessage = request.getParameter("message");
String responseNumber = request.getParameter("number");
System.out.println(responseMessage+responseNumber);
}

}

我已经在eclipse中安装了tomcat插件。当我右键单击项目然后单击在服务器上运行项目时。 tomcat 服务器在 eclipse 中启动并显示 index.html 页面..但是当我在字段中输入一些值并单击提交时..它给出了 404 错误..我过去 2 小时一直在苦苦挣扎..请帮助..还有..仅供引用,我正在使用本教程 http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html

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