我有tomcat 7.0.14,jdk1.6和Eclipse Indigo for Java EE Web應用程序開發人員。 我是JSP新手,所以嘗試過Eclipse,因爲我認爲它使編碼變得更容易。我緊跟着this video tutorial。Eclipse 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>
Username: <input type=text name="user"><br><br>
Password: <input type=text name="pass"><br><br>
<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>
請注意,如果答案適合您,您應該將其標記爲已接受。 – Bozho 2011-06-01 15:55:00