Advertisement
Guest User

Untitled

a guest
Dec 5th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. package Servlet_bib;
  2.  
  3. import java.io.IOException;
  4. import java.util.List;
  5.  
  6. import javax.ejb.EJB;
  7. import javax.naming.Context;
  8. import javax.naming.InitialContext;
  9. import javax.naming.NamingException;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.annotation.WebServlet;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import javax.servlet.http.HttpSession;
  16.  
  17. import couche.DAO.Adherent;
  18. import couche.DAO.Enseignant;
  19. import couche.DAO.Etudiant;
  20. import couche.metier.LibraryLocal;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. @WebServlet(name="cs", urlPatterns={"/controleur"})
  29. public class Controleur_servlet extends HttpServlet{
  30. @EJB
  31. private LibraryLocal metier ;
  32. private Boolean v =false;
  33.  
  34.  
  35.  
  36.  
  37. @Override
  38. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  39. throws ServletException, IOException {
  40. metier.AjouterEnseignant(new Enseignant());
  41. metier.AjouterAdherent(new Adherent());
  42. HttpSession session = request.getSession();
  43.  
  44.  
  45. if(session.getAttribute("logind") != "work") {
  46. String test= "<div class=\"col-md-4 col-md-push-1 animate-box\" data-animate-effect=\"fadeInRight\">\r\n" +
  47. " <div class=\"form-wrap\">\r\n" +
  48. " <div class=\"tab\">\r\n" +
  49. " <ul class=\"tab-menu\">\r\n" +
  50. " <li class=\"active gtco-first\"><a href=\"#\" data-tab=\"signup\">Login</a></li>\r\n" +
  51. " \r\n" +
  52. " </ul>\r\n" +
  53. " <div class=\"tab-content\">\r\n" +
  54. "\r\n" +
  55. " <div class=\"tab-content-inner active\" data-content=\"signup\">\r\n" +
  56. " <form method=\"post\">\r\n" +
  57. " <div class=\"row form-group\">\r\n" +
  58. " <div class=\"col-md-12\">\r\n" +
  59. " <label for=\"username\">Email</label>\r\n" +
  60. " <input type=\"text\" class=\"form-control\" id=\"username\" name=\"email\">\r\n" +
  61. " </div>\r\n" +
  62. " </div>\r\n" +
  63. " <div class=\"row form-group\">\r\n" +
  64. " <div class=\"col-md-12\">\r\n" +
  65. " <label for=\"password\">password</label>\r\n" +
  66. " <input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\">\r\n" +
  67. " </div>\r\n" +
  68. " </div>\r\n" +
  69. " \r\n" +
  70. "\r\n" +
  71. " <div class=\"row form-group\">\r\n" +
  72. " <div class=\"col-md-12\">\r\n" +
  73. " <input type=\"submit\" class=\"btn btn-primary\" value=\"Login\" name=\"submit\">\r\n" +
  74. " </div>\r\n" +
  75. " </div>\r\n" +
  76. " </form> \r\n" +
  77. " </div>\r\n" +
  78. "\r\n" +
  79. " \r\n" +
  80. " </div>\r\n" +
  81. " </div>\r\n" +
  82. " </div>\r\n" +
  83. " </div>";
  84. request.setAttribute("test", test);
  85. }
  86.  
  87. if(session.getAttribute("logind") == "work") {
  88.  
  89. String afflogout="<li><a href='?id=78'>logout</a></li>";
  90. request.setAttribute("afflogout",afflogout);
  91. String idl = request.getParameter("id");
  92. if(idl!=null) {
  93. if(idl.equals("78")) {
  94. session.removeAttribute("logind");
  95. response.sendRedirect("./controleur");
  96.  
  97. }
  98. }
  99. String interface_cher=" <div id=\"gtco-subscribe\">\r\n" +
  100. " <div class=\"gtco-container\">\r\n" +
  101. " <div class=\"row animate-box fadeInUp animated-fast\">\r\n" +
  102. " <div class=\"col-md-8 col-md-offset-2 text-center gtco-heading\">';\r\n" +
  103. " <h2>find the book </h2>\r\n" +
  104. " \r\n" +
  105. " </div>\r\n" +
  106. " </div>\r\n" +
  107. " <div class=\"row animate-box fadeInUp animated-fast\">\r\n" +
  108. " <div class=\"col-md-8 col-md-offset-2\">\r\n" +
  109. " <form method=\"post\" name=\"form_login\" onsubmit=\"return Is"
  110. + "Empty()\">\r\n" +
  111. " <form class=\"form-inline\">\r\n" +
  112. " <div class=\"col-md-6 col-sm-6\">\r\n" +
  113. " <div class=\"form-group\">\r\n" +
  114. " <label for=\"email\" class=\"sr-only\">book name</label>\r\n" +
  115. " <input type=\"text\" name=\"bokkr\" class=\"form-control\" id=\"email\" placeholder=\"book name\">\r\n" +
  116. " </div>\r\n" +
  117. " </div>\r\n" +
  118. " <div class=\"col-md-6 col-sm-6\">\r\n" +
  119. " <button type=\"submit\" name=\"finder\" class=\"btn btn-default btn-block\" value='FIND'>FIND</button>\r\n" +
  120. " </div>\r\n" +
  121. " </form>\r\n" +
  122. " </form>\r\n" +
  123. " </div>\r\n" +
  124. " </div>\r\n" +
  125. " </div>\r\n" +
  126. " </div>";
  127. request.setAttribute("interface_cher", interface_cher);
  128.  
  129.  
  130.  
  131.  
  132. }
  133.  
  134.  
  135. request.getRequestDispatcher("Home.jsp").forward(request, response);
  136.  
  137.  
  138.  
  139. }
  140.  
  141. @Override
  142. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  143. throws ServletException, IOException {
  144. String user =request.getParameter("email");
  145. String pass =request.getParameter("password");
  146. String action=request.getParameter("submit");
  147. if(action!=null) {
  148. if(action.equals("Login")) {
  149.  
  150.  
  151.  
  152. int ad = metier.RechercheAdherent(user, pass);
  153.  
  154. if(ad!=0) {
  155.  
  156. HttpSession session = request.getSession();
  157. session.setAttribute("logind", "work");
  158.  
  159.  
  160. }
  161. else {
  162. String testlogin="<script>alert(\"user or pass incorecte\");</script>";
  163. request.setAttribute("testlogin",testlogin);
  164. }
  165. }
  166.  
  167.  
  168.  
  169. }
  170. String mot_livre=request.getParameter("bokkr");
  171.  
  172. String action_recherche=request.getParameter("finder");
  173. if(action_recherche!=null) {
  174. if(action_recherche.equals("FIND")) {
  175. String affiche_book ="<div><form method='post'><table border='1'>\r\n" +
  176. "<tr><td><img src=\"./images/v.png\" height=\"130\" width=\"130\"></td>\r\n" +
  177. "<td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test0</td>\r\n" +
  178. "<td><button name='reservation' value='test' class='btn btn-default btn-block'> reserver</button></td></tr>\r\n" +
  179. "</table></form></div>";
  180. request.setAttribute("affiche_book",affiche_book);
  181.  
  182.  
  183. }
  184. }
  185. doGet(request, response);
  186. }
  187.  
  188.  
  189.  
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement