├── README.md ├── WebContent ├── Error.jsp ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ ├── lib │ │ ├── antlr-2.7.7.jar │ │ ├── byte-buddy-1.8.17.jar │ │ ├── classmate-1.3.4.jar │ │ ├── dom4j-2.1.1.jar │ │ ├── hibernate-commons-annotations-5.0.4.Final.jar │ │ ├── hibernate-core-5.3.7.Final.jar │ │ ├── jandex-2.0.5.Final.jar │ │ ├── javassist-3.23.1-GA.jar │ │ ├── javax.activation-api-1.2.0.jar │ │ ├── javax.persistence-api-2.2.jar │ │ ├── jboss-logging-3.3.2.Final.jar │ │ ├── jboss-transaction-api_1.2_spec-1.1.1.Final.jar │ │ ├── jsp-api-2.2.jar │ │ ├── jstl-1.2.jar │ │ ├── mysql-connector-java-8.0.13.jar │ │ ├── protobuf-java-3.6.1.jar │ │ └── servlet-api-2.5.jar │ └── web.xml ├── user-form.jsp └── user-list.jsp ├── build └── classes │ └── net │ └── javaguides │ └── usermanagement │ ├── dao │ └── UserDao.class │ ├── model │ └── User.class │ ├── utl │ └── HibernateUtil.class │ └── web │ └── UserServlet.class ├── sql └── create-user-table.sql └── src └── net └── javaguides └── usermanagement ├── dao └── UserDao.java ├── model └── User.java ├── utl └── HibernateUtil.java └── web └── UserServlet.java /README.md: -------------------------------------------------------------------------------- 1 | # jsp-servlet-hibernate-mysql-tutorial 2 | User Management web application using JSP, Servlet, and Hibernate. This web application manages a collection of users with the basic feature: list, insert, update, delete (or CURD operations - Create, Update, Read and Delete). 3 | 4 | JSP Servlet Hibernate CRUD Example - 5 | 6 | https://www.javaguides.net/2019/03/jsp-servlet-hibernate-crud-example.html 7 | -------------------------------------------------------------------------------- /WebContent/Error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isErrorPage="true" %> 3 | 5 | 6 | 7 | Error 8 | 9 | 10 |
11 |

Error

12 |

<%=exception.getMessage() %>

13 |
14 | 15 | -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/antlr-2.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/antlr-2.7.7.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/byte-buddy-1.8.17.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/byte-buddy-1.8.17.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/classmate-1.3.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/classmate-1.3.4.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/dom4j-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/dom4j-2.1.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/hibernate-commons-annotations-5.0.4.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/hibernate-commons-annotations-5.0.4.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/hibernate-core-5.3.7.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/hibernate-core-5.3.7.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jandex-2.0.5.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/jandex-2.0.5.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/javassist-3.23.1-GA.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/javassist-3.23.1-GA.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/javax.activation-api-1.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/javax.activation-api-1.2.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/javax.persistence-api-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/javax.persistence-api-2.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jboss-logging-3.3.2.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/jboss-logging-3.3.2.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jsp-api-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/jsp-api-2.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jstl-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/jstl-1.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/protobuf-java-3.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/protobuf-java-3.6.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/servlet-api-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/WebContent/WEB-INF/lib/servlet-api-2.5.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | User Management Web Application 8 | 9 | 10 | java.lang.Exception 11 | /Error.jsp 12 | 13 | -------------------------------------------------------------------------------- /WebContent/user-form.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | 5 | 6 | User Management Application 7 | 8 | 9 |
10 |

User Management

11 |

12 | Add New User 13 |     14 | List All Users 15 | 16 |

17 |
18 |
19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 46 | 47 | 48 | 49 | 54 | 55 | 56 | 57 | 62 | 63 | 64 | 67 | 68 |
27 |

28 | 29 | Edit User 30 | 31 | 32 | Add New User 33 | 34 |

35 |
User Name: 42 | 45 |
User Email: 50 | 53 |
Country: 58 | 61 |
65 | 66 |
69 |
70 |
71 | 72 | 73 | -------------------------------------------------------------------------------- /WebContent/user-list.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | 5 | 6 | User Management Application 7 | 8 | 9 |
10 |

User Management

11 |

12 | Add New User 13 |     14 | List All Users 15 | 16 |

17 |
18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 39 | 40 | 41 |

List of Users

IDNameEmailCountryActions
35 | Edit 36 |      37 | Delete 38 |
42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /build/classes/net/javaguides/usermanagement/dao/UserDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/build/classes/net/javaguides/usermanagement/dao/UserDao.class -------------------------------------------------------------------------------- /build/classes/net/javaguides/usermanagement/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/build/classes/net/javaguides/usermanagement/model/User.class -------------------------------------------------------------------------------- /build/classes/net/javaguides/usermanagement/utl/HibernateUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/build/classes/net/javaguides/usermanagement/utl/HibernateUtil.class -------------------------------------------------------------------------------- /build/classes/net/javaguides/usermanagement/web/UserServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/jsp-servlet-hibernate-mysql-tutorial/ae3487a398bd74d7089af79de7127cf6d1d90bfa/build/classes/net/javaguides/usermanagement/web/UserServlet.class -------------------------------------------------------------------------------- /sql/create-user-table.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE 'demo'; 2 | USE demo; 3 | 4 | create table users ( 5 | id int(3) NOT NULL AUTO_INCREMENT, 6 | name varchar(120) NOT NULL, 7 | email varchar(220) NOT NULL, 8 | country varchar(120), 9 | PRIMARY KEY (id) 10 | ); 11 | 12 | -------------------------------------------------------------------------------- /src/net/javaguides/usermanagement/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.usermanagement.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.hibernate.Session; 6 | import org.hibernate.Transaction; 7 | 8 | import net.javaguides.usermanagement.model.User; 9 | import net.javaguides.usermanagement.utl.HibernateUtil; 10 | 11 | /** 12 | * CRUD database operations 13 | * @author Ramesh Fadatare 14 | * 15 | */ 16 | public class UserDao { 17 | 18 | /** 19 | * Save User 20 | * @param user 21 | */ 22 | public void saveUser(User user) { 23 | Transaction transaction = null; 24 | try (Session session = HibernateUtil.getSessionFactory().openSession()) { 25 | // start a transaction 26 | transaction = session.beginTransaction(); 27 | // save the student object 28 | session.save(user); 29 | // commit transaction 30 | transaction.commit(); 31 | } catch (Exception e) { 32 | if (transaction != null) { 33 | transaction.rollback(); 34 | } 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | /** 40 | * Update User 41 | * @param user 42 | */ 43 | public void updateUser(User user) { 44 | Transaction transaction = null; 45 | try (Session session = HibernateUtil.getSessionFactory().openSession()) { 46 | // start a transaction 47 | transaction = session.beginTransaction(); 48 | // save the student object 49 | session.update(user); 50 | // commit transaction 51 | transaction.commit(); 52 | } catch (Exception e) { 53 | if (transaction != null) { 54 | transaction.rollback(); 55 | } 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | /** 61 | * Delete User 62 | * @param id 63 | */ 64 | public void deleteUser(int id) { 65 | 66 | Transaction transaction = null; 67 | try (Session session = HibernateUtil.getSessionFactory().openSession()) { 68 | // start a transaction 69 | transaction = session.beginTransaction(); 70 | 71 | // Delete a user object 72 | User user = session.get(User.class, id); 73 | if (user != null) { 74 | session.delete(user); 75 | System.out.println("user is deleted"); 76 | } 77 | 78 | // commit transaction 79 | transaction.commit(); 80 | } catch (Exception e) { 81 | if (transaction != null) { 82 | transaction.rollback(); 83 | } 84 | e.printStackTrace(); 85 | } 86 | } 87 | 88 | /** 89 | * Get User By ID 90 | * @param id 91 | * @return 92 | */ 93 | public User getUser(int id) { 94 | 95 | Transaction transaction = null; 96 | User user = null; 97 | try (Session session = HibernateUtil.getSessionFactory().openSession()) { 98 | // start a transaction 99 | transaction = session.beginTransaction(); 100 | // get an user object 101 | user = session.get(User.class, id); 102 | // commit transaction 103 | transaction.commit(); 104 | } catch (Exception e) { 105 | if (transaction != null) { 106 | transaction.rollback(); 107 | } 108 | e.printStackTrace(); 109 | } 110 | return user; 111 | } 112 | 113 | /** 114 | * Get all Users 115 | * @return 116 | */ 117 | @SuppressWarnings("unchecked") 118 | public List getAllUser() { 119 | 120 | Transaction transaction = null; 121 | List listOfUser = null; 122 | try (Session session = HibernateUtil.getSessionFactory().openSession()) { 123 | // start a transaction 124 | transaction = session.beginTransaction(); 125 | // get an user object 126 | 127 | listOfUser = session.createQuery("from User").getResultList(); 128 | 129 | // commit transaction 130 | transaction.commit(); 131 | } catch (Exception e) { 132 | if (transaction != null) { 133 | transaction.rollback(); 134 | } 135 | e.printStackTrace(); 136 | } 137 | return listOfUser; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/net/javaguides/usermanagement/model/User.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.usermanagement.model; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | /** 11 | * User.java 12 | * This is a model class represents a User entity 13 | * @author Ramesh Fadatare 14 | * 15 | */ 16 | 17 | @Entity 18 | @Table(name="instructor") 19 | public class User { 20 | 21 | @Id 22 | @GeneratedValue(strategy=GenerationType.IDENTITY) 23 | @Column(name="id") 24 | protected int id; 25 | 26 | @Column(name="name") 27 | protected String name; 28 | 29 | @Column(name="email") 30 | protected String email; 31 | 32 | @Column(name="country") 33 | protected String country; 34 | 35 | public User() { 36 | } 37 | 38 | public User(String name, String email, String country) { 39 | super(); 40 | this.name = name; 41 | this.email = email; 42 | this.country = country; 43 | } 44 | 45 | public User(int id, String name, String email, String country) { 46 | super(); 47 | this.id = id; 48 | this.name = name; 49 | this.email = email; 50 | this.country = country; 51 | } 52 | 53 | public int getId() { 54 | return id; 55 | } 56 | public void setId(int id) { 57 | this.id = id; 58 | } 59 | public String getName() { 60 | return name; 61 | } 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | public String getEmail() { 66 | return email; 67 | } 68 | public void setEmail(String email) { 69 | this.email = email; 70 | } 71 | public String getCountry() { 72 | return country; 73 | } 74 | public void setCountry(String country) { 75 | this.country = country; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/net/javaguides/usermanagement/utl/HibernateUtil.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.usermanagement.utl; 2 | 3 | import java.util.Properties; 4 | 5 | import org.hibernate.SessionFactory; 6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 7 | import org.hibernate.cfg.Configuration; 8 | import org.hibernate.cfg.Environment; 9 | import org.hibernate.service.ServiceRegistry; 10 | 11 | import net.javaguides.usermanagement.model.User; 12 | 13 | /** 14 | * Java based configuration 15 | * @author ramesh Fadatare 16 | * 17 | */ 18 | public class HibernateUtil { 19 | private static SessionFactory sessionFactory; 20 | 21 | public static SessionFactory getSessionFactory() { 22 | if (sessionFactory == null) { 23 | try { 24 | Configuration configuration = new Configuration(); 25 | 26 | // Hibernate settings equivalent to hibernate.cfg.xml's properties 27 | Properties settings = new Properties(); 28 | settings.put(Environment.DRIVER, "com.mysql.jdbc.Driver"); 29 | settings.put(Environment.URL, "jdbc:mysql://localhost:3306/demo?useSSL=false"); 30 | settings.put(Environment.USER, "root"); 31 | settings.put(Environment.PASS, "root"); 32 | settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect"); 33 | 34 | settings.put(Environment.SHOW_SQL, "true"); 35 | 36 | settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); 37 | 38 | settings.put(Environment.HBM2DDL_AUTO, "create-drop"); 39 | 40 | configuration.setProperties(settings); 41 | configuration.addAnnotatedClass(User.class); 42 | 43 | ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() 44 | .applySettings(configuration.getProperties()).build(); 45 | System.out.println("Hibernate Java Config serviceRegistry created"); 46 | sessionFactory = configuration.buildSessionFactory(serviceRegistry); 47 | return sessionFactory; 48 | 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | return sessionFactory; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/net/javaguides/usermanagement/web/UserServlet.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.usermanagement.web; 2 | 3 | import java.io.IOException; 4 | import java.sql.SQLException; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import net.javaguides.usermanagement.dao.UserDao; 15 | import net.javaguides.usermanagement.model.User; 16 | 17 | /** 18 | * ControllerServlet.java 19 | * This servlet acts as a page controller for the application, handling all 20 | * requests from the user. 21 | * @email Ramesh Fadatare 22 | */ 23 | 24 | @WebServlet("/") 25 | public class UserServlet extends HttpServlet { 26 | private static final long serialVersionUID = 1L; 27 | private UserDao userDao; 28 | 29 | public void init() { 30 | userDao = new UserDao(); 31 | } 32 | 33 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 34 | throws ServletException, IOException { 35 | doGet(request, response); 36 | } 37 | 38 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 39 | throws ServletException, IOException { 40 | String action = request.getServletPath(); 41 | 42 | try { 43 | switch (action) { 44 | case "/new": 45 | showNewForm(request, response); 46 | break; 47 | case "/insert": 48 | insertUser(request, response); 49 | break; 50 | case "/delete": 51 | deleteUser(request, response); 52 | break; 53 | case "/edit": 54 | showEditForm(request, response); 55 | break; 56 | case "/update": 57 | updateUser(request, response); 58 | break; 59 | default: 60 | listUser(request, response); 61 | break; 62 | } 63 | } catch (SQLException ex) { 64 | throw new ServletException(ex); 65 | } 66 | } 67 | 68 | private void listUser(HttpServletRequest request, HttpServletResponse response) 69 | throws SQLException, IOException, ServletException { 70 | List listUser = userDao.getAllUser(); 71 | request.setAttribute("listUser", listUser); 72 | RequestDispatcher dispatcher = request.getRequestDispatcher("user-list.jsp"); 73 | dispatcher.forward(request, response); 74 | } 75 | 76 | private void showNewForm(HttpServletRequest request, HttpServletResponse response) 77 | throws ServletException, IOException { 78 | RequestDispatcher dispatcher = request.getRequestDispatcher("user-form.jsp"); 79 | dispatcher.forward(request, response); 80 | } 81 | 82 | private void showEditForm(HttpServletRequest request, HttpServletResponse response) 83 | throws SQLException, ServletException, IOException { 84 | int id = Integer.parseInt(request.getParameter("id")); 85 | User existingUser = userDao.getUser(id); 86 | RequestDispatcher dispatcher = request.getRequestDispatcher("user-form.jsp"); 87 | request.setAttribute("user", existingUser); 88 | dispatcher.forward(request, response); 89 | 90 | } 91 | 92 | private void insertUser(HttpServletRequest request, HttpServletResponse response) 93 | throws SQLException, IOException { 94 | String name = request.getParameter("name"); 95 | String email = request.getParameter("email"); 96 | String country = request.getParameter("country"); 97 | User newUser = new User(name, email, country); 98 | userDao.saveUser(newUser); 99 | response.sendRedirect("list"); 100 | } 101 | 102 | private void updateUser(HttpServletRequest request, HttpServletResponse response) 103 | throws SQLException, IOException { 104 | int id = Integer.parseInt(request.getParameter("id")); 105 | String name = request.getParameter("name"); 106 | String email = request.getParameter("email"); 107 | String country = request.getParameter("country"); 108 | 109 | User user = new User(id, name, email, country); 110 | userDao.updateUser(user); 111 | response.sendRedirect("list"); 112 | } 113 | 114 | private void deleteUser(HttpServletRequest request, HttpServletResponse response) 115 | throws SQLException, IOException { 116 | int id = Integer.parseInt(request.getParameter("id")); 117 | userDao.deleteUser(id); 118 | response.sendRedirect("list"); 119 | } 120 | } 121 | --------------------------------------------------------------------------------