Join us on Facebook

Please wait..10 Seconds Cancel

11.16.2013

// // Leave a Comment

A simple JSP form which will take inputs from user and store that in Database

submit_form.jsp

 
<%@ 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>Submit Form</title> 
</head> 
<body> 
  <center> 
  <form method="POST" action="submit_in.jsp" > 
  <table border="1"> 
    <tr> 
      <td>Name</td><td><input name="c_name" type="text"></input></td> 
    </tr> 
    <tr> 
      <td>Surname</td><td><input name="c_surname" 
type="text"></input></td> 
    </tr> 
    <tr> 
      <td>Email</td><td><input name="c_email" type="text"></input></td> 
    </tr> 
    <tr> 
      <td>Address</td><td><textarea name="c_address" 
rows="4"></textarea></td> 
    </tr> 
    <tr> 
      <td></td><td><input type="reset" value="Reset"><input 
type="submit" value="Submit"></td> 
    </tr> 
  </table> 
  </form> 
  </center> 
</body> 
</html> 

submit_in.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1" import="java.sql.*"%> 
<!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>Submit From</title> 
</head> 
<body> 
<% 
String name=request.getParameter("c_name"); 
String surname=request.getParameter("c_surname"); 
String address=request.getParameter("c_address"); 
String email=request.getParameter("c_email"); 
//Connector Section 
String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; 
String url = "jdbc:odbc:SubmitDetailsDB"; 
String username = ""; 
String password = "";  
Connection c; 
Statement statement; 
 
Class.forName(driver); 
c= DriverManager.getConnection(url, username, password); 
try 
{ 
  String query="INSERT INTO Students (Name,Surname,Address,Email) VALUES ('"+ 
  name+"','"+surname+"','"+address+"','"+email+"')"; 
  statement = (Statement) c.createStatement(); 
  statement.executeUpdate(query); 
  out.println("Submit SUcessful!!"); 
} 
catch(Exception e) 
{ 
  System.out.println(e); 
} 
 
%> 
</body> 
</html>  

0 comments:

Post a Comment