
Develop a JSP page (with some fields) with all the JSP tags with a submit button.Make the JSP page to communicate with the database

1)student.jsp:
<html> <form method="post" action="insertstudent.jsp"> <table> <tr><td>Name:</td><td><input type="text" name="name"></td></tr> <tr><td>Address:</td><td><input type="text" name="address"></td></tr> <tr><td>Gender:</td><td>M<input type="radio" name="gen" value="Male">F<input type="radio" name="gen" value="Female"></td></tr> <tr><td>Qualification:</td><td><select name="qualification"> <option value="-1">--Select--</option> <option value="BBA">BBA</option> <option value="BCA">BCA</option> <option value="Btech">Btech</option> <option value="MBA">MBA</option> <option value="MCA">MCA</option> </select></td></tr> <tr> <td>Languages:</td><td><input type="checkbox" value="Hindi">Hindi<input type="checkbox" name="check" value="English">English<input type="checkbox" name="check" value="French">French<input type="checkbox" name="check" value="German">German</td></tr> <tr><td></td><td><input type="submit" value="Submit"></td></tr> </table> </form> </html>
2)insertstudent.jsp:
<%@page import="java.sql.*,java.util.*"%>
<%
String name=request.getParameter("name");
String address=request.getParameter("address");
String gen=request.getParameter("gen");
String qualification=request.getParameter("Qualification");
String languages[]=request.getParameterValues("check");
String lang="";
for(int i=0;i<languages.length;i++){
lang+=languages[i]+" ";
}
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
PreparedStatement pst=con.prepareStatement("insert into student(name, address,gender,qualification,languages)values(?,?,?,?,?)");
pst.setString(1, name);
pst.setString(2, address);
pst.setString(3, gen);
pst.setString(4, qualification);
pst.setString(5, lang);
pst.executeUpdate();
con.close();
out.println("Data is successfully inserted into database.");
}
catch(Exception e){
System.out.println(e);
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.