You are required to create a Java Web application to manage students information
ID: 3709435 • Letter: Y
Question
You are required to create a Java Web application to manage students information using ISP, Servlets and MySQL Database. 1. Create a new MysQL database coLLEGE that has one table STUDENTS. Each student has ID, FIRSTNAME, LASTNAME, EMAIL, SCORE1,SCORE2,SCORES, and AVERAGE.(1 Mark) Create a jsp page "index.jspehat has 2hyperlinks, Profess? r and Students Professor will link to the jsp page "professor.jsp", and Students will link to the page "students.jsp .(1 Mark) 2. 3. Create a jsp page "professor.isp". This page will have 2 hyperlinks Insert Student and View Students insert. students ID, 1" name, last name. Email, and 3 test scores, Also add a submit button to send the student details to a servlet page "insertstudent.java" that will save the data in the students table. (2 Marks) 4. The hyperlink View students shall display in a jsp page "display jsp" all of the students details 5. Insert a button Edit to modify the student's 1 name, last name, email, and the 3 scores 6. Insert a button delete that shall delete the student record. (1 Mark) 7. Create a jsp page "student.jsp" this page contains one text inout and one button. The student with the average of the 3 test scores. (2 Marks) The average should not be edit. (1 Marks) shall insert her/his ID then submit it to a servlet page "studentdetails java". This servlet shall display the student details depending on the ID. (2 Marks) Notes - Make sure that the glassfish server and the DB server are running - Use the connection class to connect to the data base. Don't forget to add to your web project the library MySQL JDBC Driver.Explanation / Answer
1. Create Database:
CREATE DATABASE IF NOT EXISTS COLLEGE;
drop table;
DROP TABLE IF EXISTS `students`;
Create table;
create table students(id varchar(10),firstname varchar(45),lastname varchar(45),email archar(45),
score1 int(3),score2 int(3),score3 int(3),average int(3));
2. index.jsp
<html>
<head>
<title>College</title>
</head>
<body>
<center>
<h1>Welcome</h1>
<h2>
<a href="professor.jsp" >professor</a><br>
<a href="students.jsp" >students</a>
</h2>
</center>
</body>
</html>
3.A). professor.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>College</title>
</head>
<body>
<center>
<h1>Professor</h1>
<a href="insert.jsp" >Insert Student</a><br>
<a href="display.jsp" >View Students</a>
</center>
</body>
</html>
3.B.) insert.jsp
<html>
<head>
<title>College</title>
</head>
<body>
<center>
<h1>Insert</h1>
<form action="insertstudent" method="POST">
<table border="0">
<tbody>
<tr>
<td>ID</td>
<td><input type="text" name="id" value="" /><br></td>
</tr>
<tr>
<td>First name</td>
<td><input type="text" name="fname" value="" /><br></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" value="" /><br></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="" /><br></td>
</tr>
<tr>
<td>Score 1</td>
<td><input type="text" name="sc1" value="" /><br></td>
</tr>
<tr>
<td>Score 2</td>
<td><input type="text" name="sc2" value="" /><br></td>
</tr>
<tr>
<td>Score 3</td>
<td><input type="text" name="sc3" value="" /><br></td>
</tr>
</tbody>
</table>
<input type="submit" value="Submit" />
</form>
</center>
</body>
</html>
3.C) Dbcon.java
package students;
import static java.lang.System.out;
import java.sql.Connection;
import java.sql.DriverManager;
public class Dbcon {
public static Connection getCon() throws ClassNotFoundException {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college", "root", "root");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}
3.D) . insertstudent.java
package students;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class insertstudent extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String id = request.getParameter("id");
int id1 = Integer.parseInt(id);
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email = request.getParameter("email");
String sc1 = request.getParameter("sc1");
int scr1 = Integer.parseInt(sc1);
String sc2 = request.getParameter("sc2");
int scr2 = Integer.parseInt(sc2);
String sc3 = request.getParameter("sc3");
int scr3 = Integer.parseInt(sc3);
int average = (scr1 + scr2 + scr2) / 3;
Connection con = students.Dbcon.getCon();
Statement st = con.createStatement();
int i = st.executeUpdate("insert into students (id,firstname,lastname,email,score1,score2,score3,average)values('" + id1 + "','" + fname + "','" + lname + "','" + email + "','" + scr1 + "','" + scr2 + "','" + scr3 + "','" + average + "')");
response.sendRedirect("insert.jsp?m=success");
} catch (Exception e) {
}
}
}
4. ) display.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="students.Dbcon"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>College </title>
</head>
<body>
<center><h2>
<table border="1">
<thead>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Score1</th>
<th>Score2</th>
<th>Score3</th>
<th>Average</th>
</tr>
</thead>
<%
Connection con = Dbcon.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from students");
while (rs.next()) {
int id = rs.getInt("id");
String firstname = rs.getString("firstname");
String lastname = rs.getString("lastname");
String email = rs.getString("email");
int scr1 = rs.getInt("score1");
int scr2 = rs.getInt("score2");
int scr3 = rs.getInt("score3");
int average = rs.getInt("average");
%>
<tbody>
<tr>
<td><%=id%></td>
<td><%=firstname%></td>
<td><%=lastname%></td>
<td><%=email%></td>
<td><%=scr1%></td>
<td><%=scr2%></td>
<td><%=scr3%></td>
<td><%=average%></td>
</tr>
</tbody>
<%
}
%>
</table>
</body>
</html>
7. A) student.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>College</title>
</head>
<body>
<form action="studentdetails" method="POST">
<center>
<h1>Enter your ID</h1><input type="text" name="id" value="" />
<input type="submit" value="Go" /></center>
</form>
</body>
</html>
7.B) Studentdetails.java
package students;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class studentdetails extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String id = request.getParameter("id");
int id1 = Integer.parseInt(id);
try {
Connection con = students.Dbcon.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from students where id='" + id1 + "'");
while (rs.next()) {
int id2 = rs.getInt("id");
String firstname = rs.getString("firstname");
String lastname = rs.getString("lastname");
String email = rs.getString("email");
int scr1 = rs.getInt("score1");
int scr2 = rs.getInt("score2");
int scr3 = rs.getInt("score3");
int average = rs.getInt("average");
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>College</title>");
out.println("</head>");
out.println("<body><center><h1> Your details are");
out.println("<h3> Id : " + id1 + "</h3>");
out.println("<h3> First Name : " + firstname + "</h3>");
out.println("<h3> Last NAme : " + lastname + "</h3>");
out.println("<h3> Email : " + email + "</h3>");
out.println("<h3> Score1 : " + scr1 + "</h3>");
out.println("<h3> score 2 : " + scr2 + "</h3>");
out.println("<h3> score 3 : " + scr3 + "</h3>");
out.println("<h3> Average : " + average + "</h3>");
out.println("</body>");
out.println("</html>");
}
} catch (Exception e) {
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.