tomcat请求的资源()不可用
我知道这是一个非常常见的问题,因为我在包括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>
位于WebContent文件夹中的html页面index.html
<!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>
最后,位于src \ com.sendreceive包com.sendreceive包中的Servlet ReceiveMessagesServlet;
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页面。.但是当我在字段中输入一些值并单击Submit..it时出现404错误。.i过去2个小时一直在苦苦挣扎。也..fyi,我正在使用本教程
http://www.ibm.com/developerworks/opensource/library/os-eclipse-
tomcat/index.html
回答:
由于action =“ / ReceiveMessagesServlet”,您收到404错误,请删除斜杠。尝试使用action =“
ReceiveMessagesServlet”。
当您在URL模式中添加斜杠时,容器将查找名称为’ReceiveMessagesServlet’的Web应用程序部署,因为此位置不存在,您将收到404错误。
以上是 tomcat请求的资源()不可用 的全部内容, 来源链接: utcz.com/qa/435570.html