Package controleur

Source Code of controleur.LoadSportifControleur

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

import dao.DAOException;
import dao.ISportifDAO;
import dao.SportifDAO;
import java.io.IOException;
import java.util.Date;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import model.Sportif;

/**
*
* @author fofana
*/
public class LoadSportifControleur extends HttpServlet {

    private DataSource dataSource;

    @Override
    public void init() throws ServletException {
        try {
            Context init = new InitialContext();
            dataSource = (DataSource) init.lookup("java:comp/env/jdbc/iphitosbd");
        } catch (NamingException ne) {
            throw new ServletException("problème lors du chargement du driver ",
                    ne);
        }
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        //response.setContentType("text/html;charset=UTF-8");
        String nomSp = "nomSp";
        String prenomSp = "prenomSp";
        //Date DateNais = "";
        String sexe = "sexe";
        Date DateInsc = null;
        String nomp = "nomP";
        String nomBat = "nomBat";
        String numLog = "nomLog";

        Sportif sp = new Sportif();
        //SportifDAO conP = new SportifDAO();

        SportifDAO Spdao = new SportifDAO(dataSource);

        try {
            //      SportifDAO sportifDAO = SportifDAO.getInstance(dataSource);
            // IdSP = Integer.parseInt(request.getParameter(arg0));
            sp.setNomSportif(request.getParameter(nomSp));
            sp.setPrenomSportif(request.getParameter(prenomSp));
            //  sp.setDateNaissance(request.getParameter(DateNais));
            sp.setSexeSportif(request.getParameter(sexe));
            //sp.setDateInscription(request.getParameter(DateInsc));
            sp.setNomPays(request.getParameter(nomp));

            sp.setNumLogement(Integer.parseInt(request.getParameter(numLog)));
            sp.setNomBatiment(request.getParameter(nomBat));
            //sp.setNumLogement(1);

            Spdao.enregistrement(sp);


            // Sportif sp = (Sportif) Session.getAttribute("Sportif");
            // SportifDAO Spdao = new SportifDAO(dataSource);
            //sp = dao.enregister(sp);
            //Spdao.enregister(sp);
            getServletContext().getRequestDispatcher("/sportifEnregistre.jsp").forward(request, response);
            return;
            //session.setAttribute("Sportif", sp);

        } catch (NumberFormatException e) {
            request.setAttribute("numLog",
                    "numero logement doit être un nombre !!!");
            getServletContext().getRequestDispatcher("/formulaireSportif.jsp").forward(request, response);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new ServletException("erreur enreigstrement sportif ", e);
        }


    }

    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    @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
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

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

Related Classes of controleur.LoadSportifControleur

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.