Package controleur

Source Code of controleur.EditerSportifControleur

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

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.servlet.jsp.tagext.TryCatchFinally;
import javax.sql.DataSource;

import org.apache.catalina.Session;
import org.apache.catalina.connector.Request;

import dao.DAOException;
import dao.SportifDAO;

import model.Sportif;

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

    private DataSource dataSource;

    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";
        //String DateNais = "DateNais";
        String sexe = "sexe";
        //Date DateInsc = null;
        String nomp = "nomP";
        String nomBat = "nombat";
        String numLog = "numLog";
        String IDSP = "Identif";
        // int IDSP = 0;
        Sportif sp = new Sportif();
        //SportifDAO conP = new SportifDAO();

        SportifDAO Spdao = new SportifDAO(dataSource);

        try {
            //      SportifDAO sportifDAO = SportifDAO.getInstance(dataSource);

            //    IDSP = getIntParameter(request, "noEtud", "Numéro de sportif incorrect");
            //IDSP = Integer.parseInt(request.getParameter(idsp));

            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.setNomBatiment(request.getParameter(nomBat));
            sp.setNumLogement(Integer.parseInt(request.getParameter(numLog)));
//      //sp.setNumLogement(1);
           
           
            //transformer les carateres de l'identifiant en int
            int idsp = Integer.parseInt(request.getParameter(IDSP));
            sp.setIdSportif(idsp);

            Spdao.editerSportif(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("/formulaireEditerSportif.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.EditerSportifControleur

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.