Package controleur

Source Code of controleur.LoadSpControleur

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package controleur;

import dao.DAOException;
import dao.SportifDAO;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Sportif;

/**
*
* @author moha
* recupere la liste des sportifs pour un pays donne
* stock la liste des sportifs dans une session
* si la requete vient de InscrirSportifEpind.jsp la liste est retourné vers InscrirSportifEpInd.jsp
* si la requete vient de formulairlListeSportif.jsp, la liste est retourne vers formulairelisteSportif.jsp
*/
public class LoadSpControleur extends AbstractControleur {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String pays = "";
        // verifie si une session est ouvert
        HttpSession session = request.getSession(true);
        try {

            pays = request.getParameter("pays");//recupere le pays

            SportifDAO dao = SportifDAO.getInstance(dataSource);
            List<Sportif> liste = dao.loadListeSportif(pays);// recupere la liste des sportifs pour un pays donnée
            if (liste == null) {
                throw new IllegalArgumentException("Pas de pays à ce nom");//on ne doit jamais rentre

            } else {

                request.setAttribute("Liste", liste);// ajoute à la sesstion la liste des sportifs

                //redirection vers la page InscrirSportifEpInd si requete émanant de inscrirsportifEpInd
                if ("inscrireSportif".equals(request.getParameter("pageOrigne"))) {
                    getServletContext().getRequestDispatcher(
                            "/InscrirSportifEpInd").forward(request, response);
                } else {
                    getServletContext().getRequestDispatcher(
                            "/formulaireListeSportif").forward(request, response);
                }
            }
            return;
        } catch (DAOException ex) {
            Logger.getLogger(ListeSportifContoleur.class.getName()).log(Level.SEVERE, null, ex);
            throw new ServletException("problème lors du chargement Sportif du pays " + pays, ex);
        } catch (IllegalArgumentException ex) {
            session.removeAttribute("Sportif");
            request.setAttribute("erreurSportif", ex.getMessage());
            getServletContext().getRequestDispatcher(
                    "/InscrirSportifEpInd").forward(request, response);
            return;
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
TOP

Related Classes of controleur.LoadSpControleur

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.