我使用 J2EE Servlet 和 tomcat 服务器 7.0.42 和 eclipse(kepler 版本),我想从 html 页面插入数据,并在按下提交按钮后将此信息插入到 mysql 表中,生成以下错误。
**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);
}
}
}