JSP, Servlet and Hibernate

parent 5e42ef14
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="defaultUnitInitialized" value="true" />
</component>
</project>
\ No newline at end of file
...@@ -11,4 +11,7 @@ ...@@ -11,4 +11,7 @@
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project> </project>
\ No newline at end of file
...@@ -38,6 +38,15 @@ ...@@ -38,6 +38,15 @@
<version>4.0.1</version> <version>4.0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.0.2.Final</version>
<type>pom</type>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.qadeer.web.services;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
public class StudentEntityManager {
public EntityManager entityManagerMethod() {
EntityManagerFactory emf= Persistence.createEntityManagerFactory("school");
EntityManager em=emf.createEntityManager();
return em;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="school">
<description>Hibernate EntityManager</description>
<class>org.example.model.Student</class>
<class>org.example.model.Course</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root1234"/>
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<body> <body>
<h1>Student List</h1> <h1>Student List</h1>
<table border='1' width='100%'> <table border='1' width='100%'>
<tr><th>Id</th><th>Name</th><th>RollNo</th><th>Age</th></tr> <tr><th>Id</th><th>Name</th><th>RollNo</th><th>Age</th><th>Edit</th><th>Delete</th></tr>
<% <%
List<Student> list = StudentDao.getAllStudents(); List<Student> list = StudentDao.getAllStudents();
......
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="school">
<description>Hibernate EntityManager</description>
<class>org.example.model.Student</class>
<class>org.example.model.Course</class>
<class>org.example.model.Teacher</class>
<class>org.example.model.Department</class>
<class>org.example.model.Book</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root1234"/>
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
#Created by Apache Maven 3.8.1
version=1.0-SNAPSHOT
groupId=org.example
artifactId=studentapp
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/servlet/DeleteServlet.java
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/dao/StudentDao.java
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/dao/UtilityDao.java
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/servlet/CreateServlet.java
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/servlet/ReadServlet.java
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/servlet/UpdateServlet.java
/Users/aqadeer/Downloads/student-jsp-servlet-master/src/main/java/com/qadeer/web/model/Student.java
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="school">
<description>Hibernate EntityManager</description>
<class>org.example.model.Student</class>
<class>org.example.model.Course</class>
<class>org.example.model.Teacher</class>
<class>org.example.model.Department</class>
<class>org.example.model.Book</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/schoolDataBase"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="charlie123"/>
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
<%@ page import = "com.qadeer.web.dao.StudentDao, com.qadeer.web.model.Student"%>
<%@ page import = "java.io.IOException, java.io.PrintWriter"%>
<h1>Update Student</h1>
<% String sid=request.getParameter("id");
int id=Integer.parseInt(sid);
Student e= StudentDao.getStudentById(id);
%>
<form action='UpdateServlet' method='post'>
<table>
<%
out.print("<tr><td></td><td><input type='hidden' name='id' value='"+e.getId()+"'/></td></tr>");
out.print("<tr><td>Name:</td><td><input type='text' name='name' value='"+e.getName()+"'/></td></tr>");
out.print("<tr><td>RollNo:</td><td><input type='rollno' name='rollno' value='"+e.getRollno()+"'/></td></tr>");
out.print("<tr><td>Age:</td><td><input type='age' name='age' value='"+e.getAge()+"'/></td></tr>");
out.print("</select>");
%>
</td></tr>
<tr><td colspan='2'><input type='submit' value='Edit & Save '/></td></tr>
</table>
</form>
<% out.close();%>
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Student app</title>
</head>
<body>
<a href="view.jsp">view all students</a>
<h1>Add New Student</h1>
<form action="CreateServlet" method="post">
<table>
<tr><td>Name:</td><td><input type="text" name="name"/></td></tr>
<tr><td>RollNo:</td><td><input type="rollno" name="rollno"/></td></tr>
<tr><td>Age:</td><td><input type="age" name="age"/></td></tr>
</td></tr>
<tr><td colspan="2"><input type="submit" value="Save Student"/></td></tr>
</table>
</form>
<h1>Search Student by Rollno</h1>
<form action="ReadServlet" method="post">
<table>
<tr><td>RollNo:</td><td><input type="rollno" name="rollno"/></td></tr>
<tr><td colspan="2"><input type="submit" value="Search student"/></td></tr>
</table>
</form>
<br/>
</body>
</html>
\ No newline at end of file
<%@page import = "com.qadeer.web.model.Student"%>
<%@page import = "com.qadeer.web.dao.StudentDao"%>
<%@page import = "java.util.*"%>
<html>
<body>
<h1>Student information</h1>
<table border='1' width='100%'>
<tr><th>Id</th><th>Name</th><th>RollNo</th><th>Age</th></tr>
<%
Student e = (Student) request.getAttribute("student");
out.print("<tr><td>"+e.getId()+"</td><td>"+e.getName()+"</td><td>"+e.getRollno()+"</td><td>"+e.getAge()+"</td><td>" + "</td><td><a href='edit.jsp?id="+e.getId()+"'>edit</a></td><td><a href='DeleteServlet?id="+e.getId()+"'>delete</a></td></tr>");
%>
</table>
</body>
</html>
\ No newline at end of file
<%@page import = "com.qadeer.web.model.Student"%>
<%@page import = "com.qadeer.web.dao.StudentDao"%>
<%@page import = "java.util.*"%>
<html>
<body>
<h1>Student List</h1>
<table border='1' width='100%'>
<tr><th>Id</th><th>Name</th><th>RollNo</th><th>Age</th><th>Edit</th><th>Delete</th></tr>
<%
List<Student> list = StudentDao.getAllStudents();
for(Student e:list){
out.print("<tr><td>"+e.getId()+"</td><td>"+e.getName()+"</td><td>"+e.getRollno()+"</td><td>"+e.getAge()+"</td><td>" + "<a href='edit.jsp?id="+e.getId()+"'>edit</a></td><td><a href='DeleteServlet?id="+e.getId()+"'>delete</a></td></tr>");
}
%>
</table>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment