Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.jmlessous.entity.Utilisateur;
- import java.io.IOException;
- import java.io.PrintWriter;
- import static java.lang.System.out;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- 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.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- *
- * @author user
- */
- @WebServlet(name = "ListRegistration", urlPatterns = {"/ListRegistration"})
- public class ListRegistration extends HttpServlet {
- /**
- * 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 List<Utilisateur> processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException, ClassNotFoundException, SQLException {
- List<Utilisateur> users = new ArrayList<Utilisateur>();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/jmlesous","root", "root");
- Statement statement = con.createStatement();
- ResultSet rs = statement.executeQuery("select * from tab_utilisateur");
- while (rs.next()) {
- Utilisateur user = new Utilisateur();
- user.setIdUser (rs.getLong("ID"));
- user.setLogin(rs.getString("LOGIN"));
- user.setNom(rs.getString("NOM"));
- user.setPrenom(rs.getString("PRENOM"));
- user.setPwd(rs.getString("PWD"));
- users.add(user);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return users;
- }
- // <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 {
- try {
- processRequest(request, response);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * 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 {
- try {
- processRequest(request, response);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- }
- <%--
- Document : ListRegistration
- Created on : 9 nov. 2016, 01:06:26
- Author : user
- --%>
- <%@page contentType="text/html"%>
- <%@page pageEncoding="UTF-8"%>
- <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
- <title>List of registration</title>
- </head>
- <body>
- <table border=1>
- <thead>
- <tr>
- <th>ID</th>
- <th>NOM</th>
- <th>PRENOM</th>
- <th>LOGIN</th>
- <th>PWD</th>
- <th colspan=2>Action</th>
- </tr>
- </thead>
- <tbody>
- <c:forEach items="${users}" var="user" begin="0">
- <tr>
- <td><c:out value="${user.ID}" /></td>
- <td><c:out value="${user.NOM}" /></td>
- <td><c:out value="${user.PRENOM}" /></td>
- <td><c:out value="${user.LOGIN}" /></td>
- <td><c:out value="${user.PWD}" /></td>
- <td><a href="UserController?action=edit&userId=<c:out value="${user.ID}"/>">Update</a></td>
- <td><a href="UserController?action=delete&userId=<c:out value="${user.ID}"/>">Delete</a></td>
- </tr>
- </c:forEach>
- </tbody>
- </table>
- </body>
- </html>
- import java.io.InputStream;
- import java.io.Serializable;
- import java.util.Date;
- import javax.persistence.Column;
- import javax.persistence.DiscriminatorColumn;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name = "tab_utilisateur")
- @DiscriminatorColumn(name = "TYPE_UTILISATEUR")
- public class Utilisateur implements Serializable{
- @Id
- @Column(name = "ID")
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long idUser;
- @Column(name = "LOGIN")
- private String login;
- @Column(name = "PWD")
- private String pwd;
- @Column(name = "NOM")
- private String nom;
- @Column(name = "PRENOM")
- private String prenom;
- @Column(name = "EMAIL")
- private String email;
- @Column(name = "DATE_DE_NAISSANCE")
- private Date dateDeNaissance;
- @Column(name = "TELEPHONE")
- private String telephone;
- @Column(name = "ADRESSE")
- private String adresse;
- // @Column(name = "PHOTO")
- // private InputStream photo;
- /**
- * Creates a new instance of Person
- */
- public Utilisateur() {
- }
- public Utilisateur(Long idUser, String login, String pwd, String nom, String prenom, String email, Date dateDeNaissance, String telephone, String adresse) {
- this.idUser = idUser;
- this.login = login;
- this.pwd = pwd;
- this.nom = nom;
- this.prenom = prenom;
- this.email = email;
- this.dateDeNaissance = dateDeNaissance;
- this.telephone = telephone;
- this.adresse = adresse;
- //this.photo=photo;
- }
- public Long getIdUser() {
- return idUser;
- }
- public void setIdUser(Long idUser) {
- this.idUser = idUser;
- }
- public String getLogin() {
- return login;
- }
- public void setLogin(String login) {
- this.login = login;
- }
- public String getPwd() {
- return pwd;
- }
- public void setPwd(String pwd) {
- this.pwd = pwd;
- }
- public String getNom() {
- return nom;
- }
- public void setNom(String nom) {
- this.nom = nom;
- }
- public String getPrenom() {
- return prenom;
- }
- public void setPrenom(String prenom) {
- this.prenom = prenom;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public Date getDateDeNaissance() {
- return dateDeNaissance;
- }
- public void setDateDeNaissance(Date dateDeNaissance) {
- this.dateDeNaissance = dateDeNaissance;
- }
- public String getTelephone() {
- return telephone;
- }
- public void setTelephone(String telephone) {
- this.telephone = telephone;
- }
- public String getAdresse() {
- return adresse;
- }
- public void setAdresse(String adresse) {
- this.adresse = adresse;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement