Java 动态Web项目(Eclipse)-->;HTTP状态404错误
在youtube上的教程之后,我正在制作我的第一个java web应用程序。这是一个动态的Web应用程序,到目前为止我编写的代码相当简单,但我遇到了HTTP 404错误的问题 My web.xml显示如下:`Java 动态Web项目(Eclipse)-->;HTTP状态404错误,java,eclipse,jsp,http,http-status-code-404,Java,Eclipse,Jsp,Http,Http Status Code 404,在youtube上的教程之后,我正在制作我的第一个java web应用程序。这是一个动态的Web应用程序,到目前为止我编写的代码相当简单,但我遇到了HTTP 404错误的问题 My 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/
<?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">
<display-name>PuzzleProject</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>
<servlet>
<description> </description>
<display-name>MyServlet</display-name>
<servlet-name>MyServlet</servlet-name>
<servlet-class>BackEnd</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
</web-app>
`
有人能告诉我我做错了什么吗?嗯。。。您的请求url是什么?您可能缺少上下文根,eclipse默认为项目名称(空格转换为“”)。希望您没有用大写字母和
web.xml
拼写index.jsp
,它必须是servletBackend.MyServlet
的完整路径
`<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Welcome, please enter a bunch of words.</h1>
<input type="text" name="words" value="">
<form action = "MyServlet">
<input type="submit" value="Send" />
</form>
</body>
</html>
package BackEnd;
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 MyServlet
*/
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public MyServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
PrintWriter print = response.getWriter();
String string = "My Name Is Steven";
print.println(string);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}