예제 #1
0
 private void actionCommander(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc) {
   int idMovie = Integer.parseInt(request.getParameter("idMovie"));
   int quantite = Integer.parseInt(request.getParameter("quantite"));
   BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
   boolean found = false;
   if (beanCaddy == null) {
     beanCaddy = new BeanCaddy();
   } else {
     for (BeanMovieCaddy beanMovieCaddy : beanCaddy.getListMovie()) {
       if (beanMovieCaddy.getId() == idMovie) {
         beanMovieCaddy.addQuantite(quantite);
         found = true;
         break;
       }
     }
   }
   if (found == false) {
     BeanResultat beanResultat = (BeanResultat) getVariableSession(request, "beanResultat");
     BeanMovieCaddy beanMovieToAdd = null;
     for (BeanMovie beanMovie : beanResultat.getListMovie()) {
       if (beanMovie.getId() == idMovie) {
         beanMovieToAdd = new BeanMovieCaddy(beanMovie);
         beanMovieToAdd.setQuantite(quantite);
         break;
       }
     }
     beanCaddy.add(beanMovieToAdd);
   }
   addVariableSession(request, "beanCaddy", beanCaddy);
   setCaddy(request, sc);
 }
예제 #2
0
 private void traitementAction(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc, String action) {
   if (action == null) {
     this.rediriger(request, response, sc, "/Accueil.jsp");
   } else if (action.equals("Recherche")) {
     this.rediriger(request, response, sc, "/Recherche.jsp");
   } else if (action.equals("Rechercher")) {
     actionRechercher(request, response, sc);
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("resultat")) {
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("getImage")) {
     int idMovie = Integer.parseInt(request.getParameter("idMovie"));
     BeanResultat beanResultat = (BeanResultat) getVariableSession(request, "beanResultat");
     LinkedList<BeanMovie> listMovie = beanResultat.getListMovie();
     for (BeanMovie beanMovie : listMovie) {
       if (beanMovie.getId() == idMovie) {
         Blob imageBlob = beanMovie.getAffiche();
         response.setContentType("image/jpeg");
         byte[] bytes;
         try {
           bytes = imageBlob.getBytes(1, (int) imageBlob.length());
           bytes = resize(bytes, 138, 97);
           response.setContentLength(bytes.length);
           response.getOutputStream().write(bytes);
           response.getOutputStream().flush();
           response.getOutputStream().close();
         } catch (Exception ex) {
           Logger.getLogger(ServletControle.class.getName()).log(Level.SEVERE, null, ex);
         }
       }
     }
   } else if (action.equals("getImageCaddy")) {
     int idMovie = Integer.parseInt(request.getParameter("idMovie"));
     BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
     LinkedList<BeanMovieCaddy> listMovie = beanCaddy.getListMovie();
     for (BeanMovieCaddy beanMovie : listMovie) {
       if (beanMovie.getId() == idMovie) {
         Blob imageBlob = beanMovie.getAffiche();
         response.setContentType("image/jpeg");
         byte[] bytes;
         try {
           bytes = imageBlob.getBytes(1, (int) imageBlob.length());
           bytes = resize(bytes, 138, 97);
           response.setContentLength(bytes.length);
           response.getOutputStream().write(bytes);
           response.getOutputStream().flush();
           response.getOutputStream().close();
         } catch (Exception ex) {
           Logger.getLogger(ServletControle.class.getName()).log(Level.SEVERE, null, ex);
         }
       }
     }
   } else if (action.equals("details")) {
     actionDetails(request, response, sc);
     this.rediriger(request, response, sc, "/Details.jsp");
   } else if (action.equals("getPage")) {
     actionGetPage(request, response, sc);
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("getPageCaddy")) {
     this.rediriger(
         request, response, sc, "/Caddy.jsp?numPage=" + request.getParameter("numPage"));
   } else if (action.equals("trier")) {
     actionTrier(request, response, sc);
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("commander")) {
     actionCommander(request, response, sc);
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else if (action.equals("deconnecter")) {
     actionDeconnecter(request, response, sc);
     rediriger(request, response, sc, "/index.jsp");
   } else if (action.equals("caddy")) {
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else if (action.equals("actionCaddy")) {
     traiterActionCaddy(request, response, sc);
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else if (action.equals("error")) {
     rediriger(request, response, sc, "/error.jsp");
   } else if (action.equals("validerCaddy")) {
     actionValiderCaddy(request, response, sc);
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else {
     this.rediriger(request, response, sc, "/Accueil.jsp");
   }
 }