我使用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);
}
}
}
答案 0 :(得分:0)
确保您的web.xml具有servlet条目...并且在tomcat中部署了Web应用程序