2015-01-07 198 views
-1

爲servlet創建文件時出現錯誤。HTTP狀態404 -/sampleServlet/

錯誤代碼:

HTTP狀態404 -/sampleServlet/ 類型狀態報告消息 /sampleServlet/ 描述所請求的資源不可用。的Apache Tomcat/8.0.0-RC5

Java代碼:sampleServlet.java

package test; 

import java.io.IOException; 
import java.io.PrintWriter; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 


public class sampleServlet extends HttpServlet{ 

    public void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws IOException{ 
     PrintWriter out = response.getWriter(); 
     out.println("<html>"); 
     out.println("<body>"); 
     out.println("<h1>Hello Servlet Get</h1>"); 
     out.println("</body>"); 
     out.println("</html>"); 
    } 
} 

JSP頁:index.jsp的

<html> 
    <body> 
    <form action="sampleServlet" method="GET"> 
     <input type="submit" value="Submit form "/> 
    </form> 
    </body> 
</html> 

web.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>faltu3</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
    <servlet> 
     <servlet-name>sampleServlet</servlet-name> 
     <servlet-class>test.sampleServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>sampleServlet</servlet-name> 
     <url-pattern>/sampleServlet</url-pattern> 
    </servlet-mapping> 
</web-app> 

請幫我解決這個錯誤。 謝謝。

回答

1

操作僅sampleServlet/sampleServlet/

<form action="sampleServlet" method="GET"> 
+0

我沒試過everyting ... :(仍然得到同樣的錯誤.. –

+0

重啓後..這是工作的感謝.. :) –