Home
Examples
Tutorials
Errata
/ch7/catalogue/CreateCatalogue.java
/ch7/catalogue/CreateCatalogue.java
package ch7.catalogue; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import shared.HibernateHelper; @WebServlet(urlPatterns={"/ch7/catalogue/CreateCatalogue"}) public class CreateCatalogue extends HttpServlet { @Override public void init() { HibernateHelper.createTable(CatalogueItem.class); HibernateHelper.initSessionFactory(CatalogueItem.class); } static final List
itemList = new ArrayList
(); static { itemList.add(new CatalogueItem( "A1", "The Foundation Trilogy", "A very fine book. Why not buy one?", 1.11)); itemList.add(new CatalogueItem( "T2", "The Hobbit", "A very fine book. Why not buy two?", 2.22)); itemList.add(new CatalogueItem( "Y3", "Light on Yoga", "A very fine book. Why not buy three?", 3.33)); itemList.add(new CatalogueItem( "M4", "Blue Monkey Sideshow", "A very fine book. Why not buy four?", 4.44)); }; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HibernateHelper.updateDB(itemList); response.getWriter().print("Catalogue Created"); destroy(); } }
Contact the author