Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controller;
- import java.io.IOException;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityManagerFactory;
- import javax.persistence.Persistence;
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletContext;
- 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 helper.HelperInserimentoProdotto;
- import action.ActionInserimentoProdotto;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityManagerFactory;
- import javax.persistence.EntityTransaction;
- import javax.persistence.Persistence;
- /**
- * Servlet implementation class Controller
- */
- @WebServlet("/controllerInserimento")
- public class ControllerInserimento extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public ControllerInserimento() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // TODO Auto-generated method stub
- //response.getWriter().append("Served at: ").append(request.getContextPath());
- String nextPage = "/inserimentoProdotto.jsp";
- ServletContext servletContext = getServletContext();
- RequestDispatcher rd = servletContext.getRequestDispatcher(nextPage);
- rd.forward(request, response);
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("products-unit");
- EntityManager em = emf.createEntityManager(); //è una classe che gestisce le entità
- HelperInserimentoProdotto helper = new HelperInserimentoProdotto();
- ActionInserimentoProdotto action = new ActionInserimentoProdotto();
- String nextPage = "/InserimentoProdotto.jsp";
- if(helper.validate(request, response)){
- nextPage = action.execute(request, emf);
- }
- nextPage = response.encodeURL(nextPage);
- ServletContext servletContext = getServletContext();
- RequestDispatcher rd = servletContext.getRequestDispatcher(nextPage);
- rd.forward(request, response);
- }
- }
- ----------------------------------------------------ERRORE------------------------------------------------------------------------
- mag 20, 2016 6:43:09 PM org.apache.catalina.startup.Catalina start
- INFORMAZIONI: Server startup in 8342 ms
- mag 20, 2016 6:43:12 PM org.apache.catalina.core.StandardWrapperValve invoke
- GRAVE: Servlet.service() for servlet [controller.ControllerInserimento] in context with path [/siw-jpa-es2] threw exception [Servlet execution threw an exception] with root cause
- java.lang.ClassNotFoundException: javax.persistence.Persistence
- at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
- at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
- at controller.ControllerInserimento.doPost(ControllerInserimento.java:52)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
- at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement