Advertisement
disiodj

siw-jpa-es2-controllerInserimentoClass

May 20th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. package controller;
  2. import java.io.IOException;
  3.  
  4. import javax.persistence.EntityManager;
  5. import javax.persistence.EntityManagerFactory;
  6. import javax.persistence.Persistence;
  7. import javax.servlet.RequestDispatcher;
  8. import javax.servlet.ServletContext;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.annotation.WebServlet;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import helper.HelperInserimentoProdotto;
  15. import action.ActionInserimentoProdotto;
  16. import javax.persistence.EntityManager;
  17. import javax.persistence.EntityManagerFactory;
  18. import javax.persistence.EntityTransaction;
  19. import javax.persistence.Persistence;
  20.  
  21. /**
  22.  * Servlet implementation class Controller
  23.  */
  24. @WebServlet("/controllerInserimento")
  25. public class ControllerInserimento extends HttpServlet {
  26. private static final long serialVersionUID = 1L;
  27.        
  28.     /**
  29.      * @see HttpServlet#HttpServlet()
  30.      */
  31.     public ControllerInserimento() {
  32.         super();
  33.         // TODO Auto-generated constructor stub
  34.     }
  35.  
  36.     /**
  37.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  38.      */
  39.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  40.         // TODO Auto-generated method stub
  41.         //response.getWriter().append("Served at: ").append(request.getContextPath());
  42.         String nextPage = "/inserimentoProdotto.jsp";
  43.         ServletContext servletContext = getServletContext();
  44.         RequestDispatcher rd = servletContext.getRequestDispatcher(nextPage);
  45.         rd.forward(request, response);
  46.     }
  47.  
  48.     /**
  49.      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  50.      */
  51.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  52.         EntityManagerFactory emf = Persistence.createEntityManagerFactory("products-unit");
  53.         EntityManager em = emf.createEntityManager(); //è una classe che gestisce le entità
  54.        
  55.         HelperInserimentoProdotto helper = new HelperInserimentoProdotto();
  56.         ActionInserimentoProdotto action = new ActionInserimentoProdotto();
  57.        
  58.         String nextPage = "/InserimentoProdotto.jsp";
  59.         if(helper.validate(request, response)){
  60.             nextPage = action.execute(request, emf);
  61.         }
  62.         nextPage = response.encodeURL(nextPage);
  63.         ServletContext servletContext = getServletContext();
  64.         RequestDispatcher rd = servletContext.getRequestDispatcher(nextPage);
  65.         rd.forward(request, response);
  66.     }
  67.  
  68. }
  69.  
  70.  
  71.  
  72. ----------------------------------------------------ERRORE------------------------------------------------------------------------
  73.  
  74. mag 20, 2016 6:43:09 PM org.apache.catalina.startup.Catalina start
  75. INFORMAZIONI: Server startup in 8342 ms
  76. mag 20, 2016 6:43:12 PM org.apache.catalina.core.StandardWrapperValve invoke
  77. GRAVE: Servlet.service() for servlet [controller.ControllerInserimento] in context with path [/siw-jpa-es2] threw exception [Servlet execution threw an exception] with root cause
  78. java.lang.ClassNotFoundException: javax.persistence.Persistence
  79.     at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
  80.     at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
  81.     at controller.ControllerInserimento.doPost(ControllerInserimento.java:52)
  82.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  83.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  84.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  85.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  86.     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement