コード例 #1
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    System.out.println("entree servlet afficheSerieTv");
    SerieTvService sserv = new SerieTvService();
    String maVue = "/vues/afficherSerieTv.jsp";

    SerieTv serie;
    try {
      serie = (SerieTv) sserv.findById(Integer.parseInt(request.getParameter("id")));

      SaisonDao saDao = new SaisonDao();
      List<Saison> saisons = saDao.findAllSaisonsBySerie(serie.getId());
      request.setAttribute("saisons", saisons);

      request.setAttribute("serie", serie);

    } catch (ObjectNotFoundException e) {
      maVue = "/exception.jsp";
      request.setAttribute("message", e.getMessage());
    } catch (NumberFormatException e) {
      maVue = "/exception.jsp";
      request.setAttribute("message", e.getMessage());
    }

    System.out.println("redirigŽ vers " + maVue);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(maVue);
    dispatcher.forward(request, response);
  }
コード例 #2
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    System.out.println("entrŽe Servelt mise ˆ jour SŽrie POST");
    String maVue = "/vues/afficherSerieTv.jsp";
    try {
      redirectionSansSession(request, response);

      request.setCharacterEncoding("UTF-8");

      if (request.getParameter("modifier") != null) {
        int id = Integer.parseInt(request.getParameter("id"));
        String nom = request.getParameter("nom");

        String resume = request.getParameter("resume");
        String genre = request.getParameter("genre");
        AbstractMediaService fservice = new AbstractMediaService();
        SerieTv f = (SerieTv) fservice.findById(id);

        if (!nom.equals("")) f.setNom(nom);
        if (!genre.equals("")) f.setGenre(genre);
        if (!resume.equals("")) f.setResume(resume);

        fservice.update(f);

        SaisonDao saDao = new SaisonDao();
        List<Saison> saisons = saDao.findAllSaisonsBySerie(id);
        request.setAttribute("saisons", saisons);

        request.setAttribute("serie", f);
      }
    } catch (ObjectNotFoundException e) {
      System.out.println("compte non trouvŽ");
      maVue = "/exception.jsp";
      request.setAttribute("message", "compte non trouvŽ");
    } catch (SessionTermineeException e) {
      maVue = "/exception.jsp";
      request.setAttribute("message", "session terminŽe");
    }
    System.out.println("redirection vers " + maVue);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(maVue);
    dispatcher.forward(request, response);
  }