我使用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);
}
}
}
你能告訴我們一些代碼,請。 – blackpanther
web.xml和server.xml也是... –
你可以粘貼你的servlet代碼嗎? – Deckard27