0% found this document useful (0 votes)
10 views2 pages

JSP & Hibernate User Management

The document contains Java code snippets for a web application that manages user data using JSP, MySQL, and Hibernate. It includes a UserDAO class for retrieving all users from the database and an Insert class for inserting new users and listing them on a JSP page. The userlist.jsp file displays the user information in a formatted table using JSTL tags.

Uploaded by

Aung Nway Oo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

JSP & Hibernate User Management

The document contains Java code snippets for a web application that manages user data using JSP, MySQL, and Hibernate. It includes a UserDAO class for retrieving all users from the database and an Insert class for inserting new users and listing them on a JSP page. The userlist.jsp file displays the user information in a formatted table using JSTL tags.

Uploaded by

Aung Nway Oo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

JSP+MySql+Hibernate

UserDAO.java

public List<User> listAllUsers() throws HibernateException {


Session session = factory.openSession();
session.beginTransaction();
List<User> users = session.createQuery("from User").list();
session.getTransaction().commit();
return users;
}

Insert.java

private void insertUser(HttpServletRequest request, HttpServletResponse response)


throws SQLException, IOException, ServletException {
String name = request.getParameter("name");
String password = request.getParameter("password");
String email = request.getParameter("email");
userDAO.insertUser(name, password, email);
listUser(request, response);
}
private void listUser(HttpServletRequest request, HttpServletResponse response)
throws SQLException, IOException, ServletException {
List<User> users = userDAO.listAllUsers();
request.setAttribute("listUser", users);
RequestDispatcher dispatcher = request.getRequestDispatcher("userlist.jsp");
dispatcher.forward(request, response);
}

1| Hibernate
userlist.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Users Management Application</title>
<link rel="stylesheet"
href="<c:url value="/resources/css/bootstrap.min.css"/>" />
</head>
<body>
<%@ include file="menu.jsp"%>
<br>
<br>
<div class="container">

<table class="table table-striped col-sm-10">


<thead class="thead-dark">

<tr>
<th>ID</th>
<th>Name</th>
<th>Password</th>
<th>Email</th>
</tr>
</thead>
<c:forEach var="user" items="${listUser}">
<tr>
<td><c:out value="${user.id}" /></td>
<td><c:out value="${user.name}" /></td>
<td><c:out value="${user.password}" /></td>
<td><c:out value="${user.email}" /></td>
</tr>
</c:forEach>
</table>

</div>

</body>
</html>

2| Hibernate

You might also like