What is the wrong in this code, it is not getting processing, when I click the submit button it forwards to this insert.jsp and blank page appears (result is failing).
/*
Form.html
*/
<html>
<form method="post" action="Insert.jsp"> //form start
<table>
<tr><td>Fname:</td><td><input type="text" name="fname"></td></tr>
<tr><td>LName:</td><td><input type="text" name="lname"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td>pass:</td><td><input type="password" name="pass"></td></tr>
<tr><td>confirm pass:</td><td><input type="password" name="cpass"></td></tr>
<tr><td>dob:</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:</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>
/*
Insert.jsp
*/
<%@page import="java.sql.*,java.util.*"%> // import
<%
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 tno=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/student", "root", "");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into student(fname,lname,email,pass,cpass,dob,age,gender,address,country,state,city,tno,mobile) values('"+fname+"','"+lname+"','"+email+"','"+pass+"','"+cpass+"','"+dob+"','"+age+"','"+gender+"',"+address+",'"+country+"','"+state+"','"+city+"','"+city+"','"+tno+"','"+mobile+"')");
out.println("Data is successfully inserted!");
}
catch(Exception e){
System.out.print(e);
e.printStackTrace();
}
%>
Your urgency isn’t our problem.
It’d be more helpful if you could cite a log message or a stack trace than “blank page” and “failing”.
When you hit the submit button, what do you expect to be displayed?
This is a bad design. You ought not have database code in your JSP. Scriptlets are a very bad idea. Learn JSTL. The
<sql>tags might even be what you need.A better idea would be a servlet between the JSP and the database that would authenticate and authorize the user, bind and validate inputs, perform the database operations on the user’s behalf, marshal the response into request or session scope, and stream the response to the page that needed to be displayed.
I’m guessing that you’d like to display the state of the database after the INSERT, so there ought to be a table showing all the values. How does your JSP know how to do that?