Question: Create a new project and make sure you add the items in the past modules such as, Hibernate, The Todo List objects, etc. Add a

Create a new project and make sure you add the items in the past modules such as, Hibernate, The Todo List objects, etc. Add a web UI, so that it runs on the Tomcat web server. You will have to add JSP code for each of the web pages (show to-do list, add a to-do item, delete a to-do item). Your to-do-list application should already be well structured, separating the back-end from the front-end, so that adding a web UI is just a matter of adding a new front-end which would call the existing back-end. This is my existing project code. Main.java

import entity.Tasktable; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityTransaction; import jakarta.persistence.Persistence; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Main todo = new Main(); int exitProgram = 0; while(exitProgram == 0) { System.out.println("---------To Do List---------"); System.out.println("1. Add Item"); System.out.println("2. Remove Item"); System.out.println("3. View List"); System.out.println("4. Exit"); System.out.print("Enter Option: "); Scanner input = new Scanner(System.in); int option = input.nextInt(); input.nextLine(); if (option == 1 ) { System.out.print("Enter to do item to add: "); String item = input.nextLine(); todo.addItem(item); } else if (option == 2 ) { System.out.print("Enter the ID of the task you like to Remove: "); int itemDel = input.nextInt(); todo.deleteItem(itemDel-1); } else if (option == 3 ) { System.out.println("----------------------------"); System.out.println("--------Current List--------"); todo.listItem(); System.out.println("----------------------------"); } else { System.out.println("Exiting To Do List"); exitProgram = 1; } } } public void listItem() { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("default"); EntityManager entityManager = entityManagerFactory.createEntityManager(); List tasks = entityManager.createQuery("SELECT t FROM Tasktable t", Tasktable.class).getResultList(); System.out.println("----------------------------"); for (Tasktable task : tasks) { System.out.println("ID: " + task.getId() + "| Task: " + task.getTasks()); } System.out.println("----------------------------"); entityManager.close(); entityManagerFactory.close(); } public void addItem(String input) { Tasktable task = new Tasktable(); task.setTasks(input); EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("default"); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction transaction = entityManager.getTransaction(); try { transaction.begin(); entityManager.persist(task); transaction.commit(); } finally { if (transaction.isActive()) { transaction.rollback(); } entityManager.close(); entityManagerFactory.close(); } } public void deleteItem(int id) { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("default"); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction transaction = entityManager.getTransaction(); try { transaction.begin(); Tasktable task = entityManager.find(Tasktable.class, id); if (task != null) { entityManager.remove(task); System.out.println("Item removed successfully"); } else { System.out.println("Item with ID " + id + " not found"); } transaction.commit(); } catch (Exception ex) { if (transaction.isActive()) { transaction.rollback(); } ex.printStackTrace(); } finally { entityManager.close(); entityManagerFactory.close(); } } public void viewItems(int id, String input) { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("default"); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction transaction = entityManager.getTransaction(); try { transaction.begin(); Tasktable task = entityManager.find(Tasktable.class, id); entityManager.remove(task); transaction.commit(); } finally { if (transaction.isActive()) { transaction.rollback(); } entityManager.close(); entityManagerFactory.close(); } } }

Tasktable.java

package entity; import jakarta.persistence.*; @Entity public class Tasktable { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id @Column(name = "id") private long id; @Basic @Column(name = "tasks") private String tasks; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getTasks() { return tasks; } public void setTasks(String tasks) { this.tasks = tasks; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Tasktable tasktable = (Tasktable) o; if (id != tasktable.id) return false; if (tasks != null ? !tasks.equals(tasktable.tasks) : tasktable.tasks != null) return false; return true; } @Override public int hashCode() { int result = (int) (id ^ (id >>> 32)); result = 31 * result + (tasks != null ? tasks.hashCode() : 0); return result; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!