<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script language="javascript"> function validate() { var productName=document.addp.productName.value; var desc=document.addp.desc.value; var features=document.addp.features.value; var price=document.addp.price.value; var quantity=document.addp.quantity.value; var thresholdLimit=document.addp.thresholdLimit.value; if(productName==null||productName=="") { alert("product name must be filled out"); return false; } if(desc==null||desc=="") { alert("description must be filled out"); return false; } if(features==null||features=="") { alert("features must be filled out"); return false; } if(quantity==null||quantity=="") { alert("quantity must be filled out"); return false; } else if(isNaN(quantity)) { alert("quantity should be a number"); return false; } if(price==null||price=="") { alert("price must be filled out"); return false; } else if(isNaN(price)) { alert("Price should be a number"); return false; } if(thresholdLimit==null||thresholdLimit=="") { alert("threshold limit must be filled out"); return false; } else if(isNaN(thresholdLimit)) { alert("Threshold limit should be a number"); return false; } } </script> </head> <body> <h2><center>TELECOM STORE INVENTORY</center></h2> <title>Add Product</title> <table> <tr> <td width="800"><p align ="center"></p></td> </tr> </table> <table align="center" border="3" cellpadding="7" cellspacing="2" > /* <tr> <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" ><a href="main1.html"> Home </a></font></td> <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" color=""><a href="main2.html"> Product </a></font></td> <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" color=""><a href="main3.html" > Stock </a></font></td> <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" color=""><a href="main4.html"> Sales Promotion </a></font></td> </tr>*/ </table> <h2><center>ADD PRODUCT MODEL</center></h2> <form name="addp" method="post" action="ProductServlet" onsubmit="return validate();"> <table align="center" cellpadding="10" cellspacing="10" > <tr> <td>Product Model Name</td> <td><input type="text" name="productName"></td> </tr> <tr> <td>Description</td> <th><input type="text" name="desc"></th> </tr> <tr> <td>Features</td> <th><input type="text" name="features"></th> </tr> <tr> <td>Price</td> <th><input type="text" name="price"></th> </tr> <tr> <td>Quantity</td> <th><input type="text" name="quantity"></th> </tr> <tr> <td>Threshold Limit</td> <th><input type="text" name="thresholdLimit"></th> </tr> <tr> <td>Eligibility for Rewards</td> <th><select name="eligibility"><option>Yes</option><option>No</option></select></th> </tr> <tr><td><center> <input type="submit" id="button" value="Add" name="addproduct"/></center></td> <td><center><input type="Reset" value="Reset"/></center></td> </tr> </table> </form> </body> </html>
The code works fine. It seems that you forget to specify your query. Anyways, if you want to insert data into database then we are providing you an example. Here it is:
1)form.html:
<html> <form method="post" action="http://localhost:8080/examples/jsp/insert.jsp"> <table> <tr><td>First Name:</td><td><input type="text" name="fname"></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lname"></td></tr> <tr><td>Email:</td><td><input type="text" name="email"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass"></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="cpass"></td></tr> <tr><td>Date Of Birth</td><td><input type="text" name="dob"></td></tr> <tr><td>Age:</td><td><input type="text" name="age"></td></tr> <tr><td>Gender</td><td><input type="text" name="gender"></td></tr> <tr><td>Address:</td><td><input type="text" name="address"></td></tr> <tr><td>Country</td><td><input type="text" name="country"></td></tr> <tr><td>State:</td><td><input type="text" name="state"></td></tr> <tr><td>City</td><td><input type="text" name="city"></td></tr> <tr><td>Telephone No:</td><td><input type="text" name="tno"></td></tr> <tr><td>Mobile:</td><td><input type="text" name="mobile"></td></tr> <tr><td></td><td><input type="submit" value="Submit"></td></tr> </table> </form> </html>
2)insert.jsp:
<%@page import="java.sql.*,java.util.*"%> <% String fname=request.getParameter("fname"); String lname=request.getParameter("lname"); String email=request.getParameter("email"); String pass=request.getParameter("pass"); String cpass=request.getParameter("cpass"); String dob=request.getParameter("dob"); int age=Integer.parseInt(request.getParameter("age")); String gender=request.getParameter("gender"); String address=request.getParameter("address"); String country=request.getParameter("country"); String state=request.getParameter("state"); String city=request.getParameter("city"); int telephone=Integer.parseInt(request.getParameter("tno")); int mobile=Integer.parseInt(request.getParameter("mobile")); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root"); Statement st=con.createStatement(); int i=st.executeUpdate("insert into student(firstname,lastname,email,pass,confirm_pass,dob,age,gender,address,country,state,city,telephone,mobile) values('"+fname+"','"+lname+"','"+email+"','"+pass+"','"+cpass+"','"+dob+"',"+age+",'"+gender+"','"+address+"','"+country+"','"+state+"','"+city+"',"+telephone+","+mobile+")"); out.println("Data is successfully inserted!"); } catch(Exception e){ System.out.print(e); e.printStackTrace(); } %>