Open zhamri opened 7 years ago
<%--
Document : page1
Created on : Nov 22, 2017, 12:29:22 AM
Author : Azimjon Khamdamov
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Info</title>
</head>
<body>
<h1>HELLO STUDENT </h1>
<h1>Please Enter Your Details</h1>
<html>
<body>
<form action = "page2.jsp" method = "POST">
Matric Number: <input type = "text" name = "matrik">
<br><br>
Full Name: <input type = "text" name = "name" />
<br><br>
Date Of Birth: <input type = "text" name = "dob" />
<br><br>
<input type = "submit" value = "Submit" />
</form>
</body>
</html>
</body>
</html>
page2.jsp
<%--
Document : page2
Created on : Nov 22, 2017, 12:59:17 AM
Author : Azimjon Khamdamov
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<h2>Here is your details</h2>
<p><b>Matric Number:</b>
<%= request.getParameter("matrik")%>
</p>
<p><b>Full Name:</b>
<%= request.getParameter("name")%>
</p>
<p><b>Date Of Birth:</b>
<%= request.getParameter("dob")%>
</p>
</html>
Reference: https://www.tutorialspoint.com/jsp/jsp_form_processing.htm
reference: https://www.youtube.com/watch?v=8NITWKX1IJI
PAGE 1
`<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<table border = "0">
<form action="page2.jsp" >
<tr>
<td> <font size="5" color="Green"><%="Matric No : " %></font></td>
<td><input type="text" name='matric' placeholder="Enter MatricNo"></td>
</tr>
<tr>
<td> <font size="5" color="Green"><%="Name: " %></font></td>
<td> <input type="text" name="name" placeholder="Enter name"></td>
<tr>
<td> <font size="5" color="Green"><%="Date of Birth : " %></font></td>
<td><input type="text" name="dob" placeholder="Enter Date of Birth"></td>
</tr>
<tr>
<td><input type="submit" value="Register"/></td></tr>
</form>
<body bgcolor="Pink">
</body>
</html>`
Page 2
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="Pink">
<%
String matric= request.getParameter("matric");
String name= request.getParameter("name");
String dob=request.getParameter("dob");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jspdb","root","1234");
Statement st =con.createStatement();
st.executeUpdate("insert into student values('"+matric+"','"+name+"','"+dob+"')");
out.println("Data successfully added to Student Database 2017");
String QueryString = "SELECT * from student";
ResultSet rs = null;
rs= st.executeQuery(QueryString);
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
</TR>
<% } %>
<%
}catch(Exception e){out.println(e);}
%>
references :https://www.roseindia.net/jdbc/display-data-database.shtml https://www.youtube.com/watch?v=8NITWKX1IJI https://www.youtube.com/watch?v=Np6lHVFjUzs
<%--
Document : page1
Created on : Nov 22, 2017, 3:24:08 AM
Author : Azimjon Khamdamov
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Database</title>
</head>
<body>
<center>
<h1>Enter Student Details</h1>
<form action="page2.jsp" >
Matric Number: <input type = "text" name = "matrikNo">
<br><br>
Full Name: <input type = "text" name = "name" />
<br><br>
Date Of Birth: <input type = "text" name = "datebirth" />
<br><br>
<input type = "submit" value = "RECORD TO DATABASE" />
</form>
</center>
</body>
</html>
<%--
Document : page2
Created on : Nov 22, 2017, 3:35:19 AM
Author : Azimjon Khamdamov
--%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DATABASE RECORD</title>
</head>
<%
String matrikNo = request.getParameter("matrikNo");
String fullname = request.getParameter("name");
String datebirth = request.getParameter("datebirth");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/studentdb", "root", "");
Statement db = con.createStatement();
db.executeUpdate("INSERT into studentinfo (matrikNo,name,datebirth)values('"+matrikNo+"','"+fullname+"','"+datebirth+"')");
out.println("");
%>
<center>
<TABLE cellpadding="10" border="2" style="background-color: whitesmoke">
<TR>
<h3>HERE IS THE DETAILS OF STUDENT
<tr>
<th>Student Matric</th>
<th>Student Name</th>
<th>Date Of Birth</th>
</tr>
<TD> <%= request.getParameter("matrikNo")%></TD>
<TD> <%= request.getParameter("name")%></TD>
<TD> <%= request.getParameter("datebirth")%></TD>
</TR>
</table>
</center>
</html>
<%-- Document : index Created on : Nov 22, 2017, 12:03:06 PM Author : thiviya --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>
Create a
page1.jsp
to add a student’s record into MySql database. The record consist of three fields.Then display all the records in
page2.jsp