2013-08-01 124 views
0

我使用J2EE Servlet和tomcat服務器7.0.42和eclipse(kepler版本),我想從html頁面插入數據並將這些信息插入到mysql表格後,按下submit按鈕後會產生如下錯誤。HTTP狀態404 - 請求的資源不可用。在java servlet

**Error After Submit button is pressed 
    HTTP Status 404 - 
    type Status report message 
    description The requested resource is not available. 
    Apache Tomcat/7.0.42** 

    InsertData.java (Servlet class) 

這裏是servlet的Java類和我創建這個文件中的數據庫連接,並從html頁面訪問數據。

package demo; 

public class InsertData extends HttpServlet 
{ 
public void doGet(HttpServletRequest request, HttpServletResponse response) 
throws IOException, ServletException 
{ 
String t1= request.getParameter("text1"); 
String t2= request.getParameter("text2"); 
String t3= request.getParameter("text3"); 
String t4= request.getParameter("text4"); 

Connection con=null; 
try 
{ 
    Class.forName("com.mysql.jdbc.Driver");    
    con=DriverManager.getConnection 
    ("jdbc:mysql://localhost:3306/servlet_demo","root",""); 


    java.sql.Statement stmt =con.createStatement(); 

    String sql= "INSERT INTO demo(text1,text2,text3,text4) 
    VALUES('"+t1+"','"+t2+"','"+t3+"','"+t4+"')" ; 
    stmt.executeQuery(sql); 
    con.close(); 

    } 
catch(SQLException sx) 
{ 
out.println(sx); 
    } 
catch(ClassNotFoundException cx) 
{ 
out.println(cx); 
    } 
} 
    } 
+4

你能告訴我們一些代碼,請。 – blackpanther

+3

web.xml和server.xml也是... –

+0

你可以粘貼你的servlet代碼嗎? – Deckard27

回答

0

請確保您的web.xml具有servlet的入口......和Web應用程序部署在Tomcat

+0

是的web.xml是servlet條目和部署的Web應用程序,但仍然錯誤不能解決 – Ravikumar

+0

感謝您的建議 – Ravikumar

相關問題