Eclipse Indigo中的Servlet JSP连接问题

问题描述

| 我有适用于Java EE Web应用程序开发人员的tomcat 7.0.14,jdk1.6和Eclipse Indigo。 我是JSP的新手,所以尝试Eclipse是因为我认为它使编码更容易。我密切关注了该视频教程。 我在监狱项目下创建了2个文件-login.java,home.html和修改过的web.xml。 当我单击登录页面(这是第一页)中的提交按钮时,它仅显示错误
   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文件之间存在一些差异。例如:我的Eclipse中的
web.xml
位于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>
Login.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,IOException {
    doGet(request,response);
}
web.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>
    

解决方法

           Firefox无法在/ D:/ eclipse / Workspace / Prisonhome / WebContent / WEB-INF / Log?user = sa&pass = sa&action = That's + me找到文件。 您需要通过真实的Web URL(而不是本地磁盘文件系统路径)打开页面。如果Tomcat在端口8080上的本地主机上运行,​​并且webapp上下文名称为
Prisonhome
,则需要通过以下方式调用它:   http:// localhost:8080 / Prisonhome / index.html 至于教程,我建议阅读Coreservlets.com教程。您可以在我们的Servlets Wiki页面底部找到链接列表。 与具体问题无关,使用GET登录并不真正安全,因为每个人都可以在URL中看到密码。自1998年起已弃用HTML
<font>
标记,请改用CSS。也不需要使用过多的
<br>
&nbsp;
标签,请改用CSS位置/边距/填充。     ,        您需要访问tomcat上的文件-即
http://localhost:8080/Prisonhome/index.html
。不要从文件浏览器启动它。 为此,您需要部署应用程序并运行服务器(tomcat)。