Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 KB | None | 0 0
  1. import com.jmlessous.entity.Utilisateur;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import static java.lang.System.out;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.servlet.ServletException;
  15. import javax.servlet.annotation.WebServlet;
  16. import javax.servlet.http.HttpServlet;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19.  
  20. /**
  21. *
  22. * @author user
  23. */
  24. @WebServlet(name = "ListRegistration", urlPatterns = {"/ListRegistration"})
  25. public class ListRegistration extends HttpServlet {
  26.  
  27. /**
  28. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  29. * methods.
  30. *
  31. * @param request servlet request
  32. * @param response servlet response
  33. * @throws ServletException if a servlet-specific error occurs
  34. * @throws IOException if an I/O error occurs
  35. */
  36. protected List<Utilisateur> processRequest(HttpServletRequest request, HttpServletResponse response)
  37. throws ServletException, IOException, ClassNotFoundException, SQLException {
  38.  
  39. List<Utilisateur> users = new ArrayList<Utilisateur>();
  40. try {
  41.  
  42. Class.forName("com.mysql.jdbc.Driver");
  43. Connection con = DriverManager.getConnection(
  44. "jdbc:mysql://localhost:3306/jmlesous","root", "root");
  45.  
  46. Statement statement = con.createStatement();
  47. ResultSet rs = statement.executeQuery("select * from tab_utilisateur");
  48. while (rs.next()) {
  49. Utilisateur user = new Utilisateur();
  50. user.setIdUser (rs.getLong("ID"));
  51. user.setLogin(rs.getString("LOGIN"));
  52. user.setNom(rs.getString("NOM"));
  53. user.setPrenom(rs.getString("PRENOM"));
  54. user.setPwd(rs.getString("PWD"));
  55.  
  56.  
  57. users.add(user);
  58. }
  59. } catch (SQLException e) {
  60. e.printStackTrace();
  61. }
  62.  
  63. return users;
  64.  
  65. }
  66.  
  67. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  68. /**
  69. * Handles the HTTP <code>GET</code> method.
  70. *
  71. * @param request servlet request
  72. * @param response servlet response
  73. * @throws ServletException if a servlet-specific error occurs
  74. * @throws IOException if an I/O error occurs
  75. */
  76. @Override
  77. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  78. throws ServletException, IOException {
  79. try {
  80. processRequest(request, response);
  81. } catch (ClassNotFoundException ex) {
  82. Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
  83. } catch (SQLException ex) {
  84. Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
  85. }
  86. }
  87.  
  88. /**
  89. * Handles the HTTP <code>POST</code> method.
  90. *
  91. * @param request servlet request
  92. * @param response servlet response
  93. * @throws ServletException if a servlet-specific error occurs
  94. * @throws IOException if an I/O error occurs
  95. */
  96. @Override
  97. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  98. throws ServletException, IOException {
  99. try {
  100. processRequest(request, response);
  101. } catch (ClassNotFoundException ex) {
  102. Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
  103. } catch (SQLException ex) {
  104. Logger.getLogger(ListRegistration.class.getName()).log(Level.SEVERE, null, ex);
  105. }
  106. }
  107.  
  108. /**
  109. * Returns a short description of the servlet.
  110. *
  111. * @return a String containing servlet description
  112. */
  113. @Override
  114. public String getServletInfo() {
  115. return "Short description";
  116. }// </editor-fold>
  117.  
  118. }
  119.  
  120. <%--
  121.  
  122. Document : ListRegistration
  123. Created on : 9 nov. 2016, 01:06:26
  124. Author : user
  125. --%>
  126.  
  127. <%@page contentType="text/html"%>
  128. <%@page pageEncoding="UTF-8"%>
  129. <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  130.  
  131.  
  132. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  133. "http://www.w3.org/TR/html4/loose.dtd">
  134. <html>
  135. <head>
  136. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  137. <title>List of registration</title>
  138. </head>
  139. <body>
  140. <table border=1>
  141. <thead>
  142. <tr>
  143. <th>ID</th>
  144. <th>NOM</th>
  145. <th>PRENOM</th>
  146. <th>LOGIN</th>
  147. <th>PWD</th>
  148. <th colspan=2>Action</th>
  149. </tr>
  150. </thead>
  151. <tbody>
  152. <c:forEach items="${users}" var="user" begin="0">
  153. <tr>
  154. <td><c:out value="${user.ID}" /></td>
  155. <td><c:out value="${user.NOM}" /></td>
  156. <td><c:out value="${user.PRENOM}" /></td>
  157. <td><c:out value="${user.LOGIN}" /></td>
  158. <td><c:out value="${user.PWD}" /></td>
  159.  
  160. <td><a href="UserController?action=edit&userId=<c:out value="${user.ID}"/>">Update</a></td>
  161. <td><a href="UserController?action=delete&userId=<c:out value="${user.ID}"/>">Delete</a></td>
  162. </tr>
  163. </c:forEach>
  164. </tbody>
  165. </table>
  166. </body>
  167. </html>
  168.  
  169. import java.io.InputStream;
  170. import java.io.Serializable;
  171. import java.util.Date;
  172. import javax.persistence.Column;
  173. import javax.persistence.DiscriminatorColumn;
  174. import javax.persistence.Entity;
  175. import javax.persistence.GeneratedValue;
  176. import javax.persistence.GenerationType;
  177. import javax.persistence.Id;
  178. import javax.persistence.Table;
  179.  
  180.  
  181.  
  182. @Entity
  183. @Table(name = "tab_utilisateur")
  184. @DiscriminatorColumn(name = "TYPE_UTILISATEUR")
  185. public class Utilisateur implements Serializable{
  186.  
  187. @Id
  188. @Column(name = "ID")
  189. @GeneratedValue(strategy = GenerationType.IDENTITY)
  190. private Long idUser;
  191.  
  192. @Column(name = "LOGIN")
  193. private String login;
  194.  
  195. @Column(name = "PWD")
  196. private String pwd;
  197.  
  198. @Column(name = "NOM")
  199. private String nom;
  200.  
  201. @Column(name = "PRENOM")
  202. private String prenom;
  203.  
  204. @Column(name = "EMAIL")
  205. private String email;
  206.  
  207. @Column(name = "DATE_DE_NAISSANCE")
  208. private Date dateDeNaissance;
  209.  
  210. @Column(name = "TELEPHONE")
  211. private String telephone;
  212.  
  213. @Column(name = "ADRESSE")
  214. private String adresse;
  215.  
  216. // @Column(name = "PHOTO")
  217. // private InputStream photo;
  218.  
  219. /**
  220. * Creates a new instance of Person
  221. */
  222. public Utilisateur() {
  223. }
  224.  
  225. public Utilisateur(Long idUser, String login, String pwd, String nom, String prenom, String email, Date dateDeNaissance, String telephone, String adresse) {
  226. this.idUser = idUser;
  227. this.login = login;
  228. this.pwd = pwd;
  229. this.nom = nom;
  230. this.prenom = prenom;
  231. this.email = email;
  232. this.dateDeNaissance = dateDeNaissance;
  233. this.telephone = telephone;
  234. this.adresse = adresse;
  235. //this.photo=photo;
  236. }
  237.  
  238. public Long getIdUser() {
  239. return idUser;
  240. }
  241.  
  242. public void setIdUser(Long idUser) {
  243. this.idUser = idUser;
  244. }
  245.  
  246. public String getLogin() {
  247. return login;
  248. }
  249.  
  250. public void setLogin(String login) {
  251. this.login = login;
  252. }
  253.  
  254. public String getPwd() {
  255. return pwd;
  256. }
  257.  
  258. public void setPwd(String pwd) {
  259. this.pwd = pwd;
  260. }
  261.  
  262. public String getNom() {
  263. return nom;
  264. }
  265.  
  266. public void setNom(String nom) {
  267. this.nom = nom;
  268. }
  269.  
  270. public String getPrenom() {
  271. return prenom;
  272. }
  273.  
  274. public void setPrenom(String prenom) {
  275. this.prenom = prenom;
  276. }
  277.  
  278. public String getEmail() {
  279. return email;
  280. }
  281.  
  282. public void setEmail(String email) {
  283. this.email = email;
  284. }
  285.  
  286. public Date getDateDeNaissance() {
  287. return dateDeNaissance;
  288. }
  289.  
  290. public void setDateDeNaissance(Date dateDeNaissance) {
  291. this.dateDeNaissance = dateDeNaissance;
  292. }
  293.  
  294. public String getTelephone() {
  295. return telephone;
  296. }
  297.  
  298. public void setTelephone(String telephone) {
  299. this.telephone = telephone;
  300. }
  301.  
  302. public String getAdresse() {
  303. return adresse;
  304. }
  305.  
  306. public void setAdresse(String adresse) {
  307. this.adresse = adresse;
  308. }
  309.  
  310.  
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement