Gee*_*oid 5 java eclipse tomcat servlets
我是 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();
}
}
Run Code Online (Sandbox Code Playgroud)
网页.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>
Run Code Online (Sandbox Code Playgroud)
索引.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 Code Online (Sandbox Code Playgroud)
我的问题
当我右键单击我的项目然后单击时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 kepler
我试图解决问题的步骤
我试过这些,
结果
我没有看到.class文件WEB-INF夹中的文件。
结果
在这个路径“tomcat7\work\Catalina\localhost\your app”中,work文件夹是空的。
如果我需要发布更多详细信息,请告诉我。
IDE 的目录结构

你的代码在 tomcat 7 和 eclipse 中确实对我有用。也许您的index.html 与您发布的不一样,因为它的目标是Sample/welcome 而不是Sample/Sample。
尖端:
<Context docBase="Sample" path="/Sample" reloadable="false" source="org.eclipse.jst.jee.server:Sample"/></Host>
如果您不仔细检查这些文件夹中的权限。再次从头开始添加您的 tomcat7 服务器。
| 归档时间: |
|
| 查看次数: |
17748 次 |
| 最近记录: |