2011-05-31 79 views
0

我有tomcat 7.0.14,jdk1.6和Eclipse Indigo for Java EE Web应用程序开发人员。 我是JSP新手,所以尝试过Eclipse,因为我认为它使编码变得更容易。我紧跟着this video tutorialEclipse Indigo中的Servlet JSP连接问题

我在我的项目prison- login.java,home.html和修改过的web.xml下创建了2个文件。 当我点击登录提交按钮(这是第1页)页面,它仅显示这样的错误:

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内容 - > 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, HttpServletResponse response) throws ServletException, 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> 
+0

请注意,如果答案适合您,您应该将其标记为已接受。 – Bozho 2011-06-01 15:55:00

回答

0

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

您需要通过真实的网址而不是本地磁盘文件系统路径打开页面。如果Tomcat运行在localhost 8080端口和web应用程序上下文名称为Prisonhome那么你需要通过

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

调用它作为教程,我建议你阅读Coreservlets.com教程。您可以在我们的Servlets wiki page的底部找到链接列表。


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

+0

非常感谢您的先生!但似乎我的tomcat没有正常启动。只要我正确设置了tomcat,我就会遵循你的建议。假设我重新安装tomcat,那么我需要进行更改以覆盖以前的tomcat指针? – sap 2011-06-01 15:51:14

+0

没什么,基本上。也就是说,当你通过下载和解压zip来安装它。只要删除提取的文件夹应该是足够的。您只需确保先关闭它。 – BalusC 2011-06-01 15:52:42

+0

现在我的tomcat工作正常。我用一个带有html和jsp文件的简单项目对它进行了测试。当我运行每个文件时,我在工作空间中得到正确的输出。但是当我重新配置服务器以包含我的项目并单击run main。它只显示“请求的资源(/Prisonhome/main.jsp)不可用”。 HTTP状态404.有什么可能丢失? – sap 2011-06-02 10:18:17

0

您需要访问tomcat的文件 - 即http://localhost:8080/Prisonhome/index.html。不要从文件浏览器启动它。

为了做到这一点,您需要部署应用程序,并且运行服务器(tomcat)。

+0

非常感谢您的先生! – sap 2011-06-01 15:51:22