0

我有用于 Java EE Web 应用程序开发人员的 tomcat 7.0.14、jdk1.6 和 Eclipse Indigo。我是 JSP 的新手,所以尝试了 Eclipse,因为我认为它使编码更容易。我密切关注这个视频教程

我在我的项目 jail-login.java、home.html 和修改过的 web.xml 下创建了 2 个文件。当我单击登录(这是第一页)页面中的提交按钮时,它只显示此错误:

   File not found
          Firefox can't find the file at /D:/eclipse/Workspace/Prisonhome/WebContent/WEB-INF/Log?user=sa&pass=sa&action=That's+me. 

我不知道将项目保存在工作区中是否不够。

视频中给出的文件位置与我的 Eclipse 文件之间存在一些差异。例如:web.xml在我的 Eclipse 中位于 servers->apache-tomcat 目录,而不是 web content->WEB_INF->lib->web.xml。那很重要么?

我的代码:index.html

<html>
<head>
    <title> Welcome :) </title>
</head>
<body>
<form action="Log" method="get">
            <B>
            <br><br><br><br><br><br><br><br><br><br><br><br>
            &nbsp;&nbsp;&nbsp;&nbsp;Username: <input type=text name="user"><br><br>
            &nbsp;&nbsp;&nbsp;&nbsp;Password: <input type=text name="pass"><br><br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit name=action value="That's me" style="background-color:666666; color:ffffff; border-color:ee0088">
            </B></font>
        </form>
    </body>
</html>

登录.java:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String uname=request.getParameter("user");
    String passwd=request.getParameter("pass");
    response.getWriter().println("<html><head>This is the response!</head>");
    response.getWriter().println("<body>Response!!</body></html>");
}

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

网页.xml:

<servlet>
    <servlet-name>Log</servlet-name>
    <servlet-class>org.prisonhome.packs.Login</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Log</servlet-name>
    <url-pattern>/Log/*</url-pattern>
</servlet-mapping>
4

2 回答 2

0

您需要访问 tomcat 上的文件 - 即http://localhost:8080/Prisonhome/index.html。不要从文件资源管理器中启动它。

要使这项工作正常进行,您需要部署应用程序并运行服务器 (tomcat)。

于 2011-05-31T17:47:37.970 回答
0

Firefox 在 /D:/eclipse/Workspace/Prisonhome/WebContent/WEB-INF/Log?user=sa&pass=sa&action=That's+me 找不到文件。

您需要通过真实的 Web URL 打开页面,而不是通过本地磁盘文件系统路径。如果 Tomcat 在 localhost 的 8080 端口上运行,并且 webapp 上下文名称是,Prisonhome那么您需要通过以下方式调用它

http://localhost:8080/Prisonhome/index.html

至于教程,我建议阅读Coreservlets.com教程。您可以在我们的Servlets wiki 页面底部找到链接列表。


与具体问题无关,使用 GET 登录并不安全,因为每个人都可以在 URL 中看到密码。HTML<font>标记自 1998 年以来已弃用,请改用 CSS。也不需要使用过多的<br>and&nbsp;标签,而是使用 CSS 位置/边距/填充。

于 2011-05-31T17:47:38.387 回答