<分区>
我是 servlet 编程的新手。
以下是我的示例 servlet 代码
示例.Java
public class Sample extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String name=req.getParameter("name");//will return value
pw.println("Welcome "+name);
pw.close();
}
}
Web.xml
<web-app>
<servlet>
<servlet-name>sampleservlet</servlet-name>
<servlet-class>Sample</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sampleservlet</servlet-name>
<url-pattern>/Sample</url-pattern>
</servlet-mapping>
</web-app>
Index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="Sample" method="get">
Enter your name<input type="text" name="name"><br>
<input type="submit" value="login">
</form>
</body>
</html>
我的问题
当我右键单击我的项目然后单击 Run as -> Run on server
时,我选择服务器,它要求我选择一个服务器,然后我选择要运行的服务器。在 Eclipse 窗口中打开一个浏览器窗口,其地址 URL 为 http://localhost:8080/Sample/。
当我点击 login
时,它给我这样的错误,
HTTP 状态 404 -/Sample/welcome
类型状态报告
留言/示例/欢迎
描述请求的资源不可用。
Apache Tomcat/7.0.62
截图
为什么我会收到这样的错误?
其他细节
服务器:apache-tomcat-7.0.62 IDE:Eclipse Java EE 开普勒
我尝试解决问题的步骤
我试过这些,
结果
我没有在 WEB-INF
文件夹中看到 .class
文件。
结果
在此路径“tomcat7\work\Catalina\localhost\your app”中,work
文件夹为空。
如果我需要发布更多详细信息,请告诉我。
来自 IDE 的目录结构