Guest User

Untitled

a guest
Feb 27th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.12 KB | None | 0 0
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <title>JSP Page</title>
  7. <link rel="stylesheet" href="css/style.css">
  8. </head>
  9. <body>
  10. <header>
  11. <div class='acLogo'>
  12. <p>Легкоатлетичний манеж </p>
  13. <p class="uabs">УАБС НБУ</p>
  14. </div>
  15.  
  16. <a href="ManyezhGallery.jsp" class="button1">Галерея</a>
  17. <a href="ManyezhRentObjectPage.jsp" class="button1">Вартість</a>
  18. <a href="ManyezhContactInformation.jsp" class="button1">Контактна інформація</a>
  19. <form action="ControllerServlet" method="post">
  20.  
  21.  
  22. <% Object isAdmin1 = request.getSession().getAttribute("isAdmin");
  23. if (isAdmin1 != null) {
  24. Boolean isAdmin = (Boolean)isAdmin1 ;
  25. if (isAdmin) {
  26. %>
  27. <input type="submit" value="Сторінка адміністратора" name="goToAdminPage" />
  28. <% }
  29. }
  30. %>
  31. <% Object isClient1 = request.getSession().getAttribute("isClient");
  32. if (isClient1 != null) {
  33. Boolean isClient = (Boolean)isClient1 ;
  34. if (isClient) {
  35. %>
  36. <input type="submit" value="Зробити замовлення" name="goToOrders" />
  37. <% }
  38. }
  39. %>
  40.  
  41. <% if (isAdmin1 == null && isClient1 == null) { %>
  42.  
  43. <div class="logIn">
  44. <input type="text" name="login1" placeholder='login'/>
  45.  
  46. <input type="password" name="password1" placeholder='password'/>
  47.  
  48. <input type="submit" value="Вхід" name="goToAccount"/>
  49.  
  50. <input type="submit" value="Реєстрація" name="goToRegistrationPage"/>
  51.  
  52. </div>
  53.  
  54.  
  55. <%
  56. }
  57. %>
  58.  
  59. </form>
  60. </header>
  61.  
  62. <h1>Сторінка Реєстрації</h1>
  63. <form class="registerPage" action="ControllerServlet" method="post">
  64. <table>
  65.  
  66. <p>Назва компанії</p>
  67.  
  68. <input type="text" name="companyName" />
  69.  
  70. <p>Адреса компанії</p>
  71.  
  72. <input type="text" name="companyAddress" />
  73.  
  74. <p>Посада</p>
  75.  
  76. <input type="text" name="position"/>
  77.  
  78. <p>Ім'я</p>
  79.  
  80. <input type="text" name="firstname" />
  81.  
  82. <p>Прізвище</p>
  83.  
  84. <input type="text" name="surname" />
  85.  
  86. <p>По батькові</p>
  87.  
  88. <input type="text" name="patronymic"/>
  89.  
  90. <p>Ваш мобільний</p>
  91.  
  92. <input type="text" name="tel"/>
  93.  
  94. <p>Електронна пошта</p>
  95.  
  96. <input type="text" name="email"/>
  97.  
  98. <p>Логін</p>
  99.  
  100. <input type="text" name="login"/>
  101.  
  102. <p>Пароль</p>
  103.  
  104. <input type="text" name="password"/>
  105.  
  106. <input class='btn' type="submit" name="toDoRegistration" value="Зареєструватися"/>
  107.  
  108. <a id="copyright" href="/Manyezh/StartPage.jsp"> На головну </a>
  109.  
  110. </form>
  111. </body>
  112. </html>
  113.  
  114. package controller;
  115.  
  116.  
  117. import java.io.IOException;
  118. import java.sql.Connection;
  119. import java.util.Date;
  120. import java.sql.DriverManager;
  121. import java.sql.SQLException;
  122. import java.text.SimpleDateFormat;
  123. import java.util.List;
  124. import java.util.logging.Level;
  125. import java.util.logging.Logger;
  126. import javax.servlet.ServletException;
  127. import javax.servlet.http.HttpServlet;
  128. import javax.servlet.http.HttpServletRequest;
  129. import javax.servlet.http.HttpServletResponse;
  130. import model.Client;
  131. import model.Orders;
  132. import model.RentObject;
  133.  
  134.  
  135. public class ControllerServlet extends HttpServlet {
  136. private static Connection connect;
  137. private static final String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  138. private static final String userName = "system";
  139. private static final String mypassword = "blink1994";
  140. private static final String className ="oracle.jdbc.driver.OracleDriver";
  141.  
  142. /**
  143. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  144. * methods.
  145. *
  146. * @param request servlet request
  147. * @param response servlet response
  148. * @throws ServletException if a servlet-specific error occurs
  149. * @throws IOException if an I/O error occurs
  150. */
  151.  
  152. @Override
  153. public void init() throws ServletException {
  154. try {
  155. super.init();
  156. Class.forName(className);
  157. try {
  158. connect = DriverManager.getConnection(url,userName, mypassword);
  159. } catch (SQLException ex) {
  160. Logger.getLogger(JDBC_Servlet.class.getName()).log(Level.INFO, null, ex);
  161. }
  162. } catch (ClassNotFoundException ex) {
  163. Logger.getLogger(JDBC_Servlet.class.getName()).log(Level.INFO, null, ex);
  164. }
  165. }
  166.  
  167.  
  168. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  169. /**
  170. * Handles the HTTP <code>GET</code> method.
  171. *
  172. * @param request servlet request
  173. * @param response servlet response
  174. * @throws ServletException if a servlet-specific error occurs
  175. * @throws IOException if an I/O error occurs
  176. */
  177. @Override
  178. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  179. throws ServletException, IOException {
  180.  
  181. }
  182.  
  183. /**
  184. * Handles the HTTP <code>POST</code> method.
  185. *
  186. * @param request servlet request
  187. * @param response servlet response
  188. * @throws ServletException if a servlet-specific error occurs
  189. * @throws IOException if an I/O error occurs
  190. */
  191. @Override
  192. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  193. throws ServletException, IOException {
  194.  
  195. ForClient forClient = new ForClient();
  196. ForAdmin forAdmin = new ForAdmin();
  197.  
  198. String buttonGoToRegistrationPage = request.getParameter("goToRegistrationPage");
  199. String buttonToDoRegistration = request.getParameter("toDoRegistration");
  200. String buttonGoToAccount = request.getParameter("goToAccount");
  201. String buttonGoToGallery = request.getParameter("goToPhoto");
  202. String buttonGoToAdminPage = request.getParameter("goToAdminPage");
  203. String buttonToDoOrder = request.getParameter("toDoOrder");
  204. String buttonSubmitOrder = request.getParameter("SubmitOrder");
  205. String goToOrders = request.getParameter("goToOrders");
  206. String buttonClientInfo = request.getParameter("ClientInfo");
  207. String deleteOrder = request.getParameter("deleteOrder");
  208. String ChangeBtn = request.getParameter("Change");
  209. String ChangeOrder = request.getParameter("ChangeOrder");
  210. String toCost = request.getParameter("toCost");
  211.  
  212.  
  213. if (goToOrders != null){
  214.  
  215. List<RentObject> rentObj = forClient.dropDownList();
  216. request.getSession().setAttribute("rentObj", rentObj);
  217.  
  218. response.sendRedirect("OrderPage.jsp");
  219.  
  220. }
  221.  
  222. if (buttonGoToRegistrationPage != null){
  223.  
  224. response.sendRedirect("Registration.jsp");
  225.  
  226. }
  227.  
  228. if (buttonToDoRegistration != null){
  229.  
  230. String companyName = request.getParameter("companyName");
  231. String companyAddress = request.getParameter("companyAddress");
  232. String position = request.getParameter("position");
  233. String firstName = request.getParameter("firstname");
  234. String surname = request.getParameter("surname");
  235. String patronymic = request.getParameter("patronymic");
  236. String tel = request.getParameter("tel");
  237. String email = request.getParameter("email");
  238. String login = request.getParameter("login");
  239. String password = request.getParameter("password");
  240.  
  241. forClient.registry(companyName,companyAddress,position,firstName,surname, patronymic,tel,email,login,password);
  242. response.sendRedirect("StartPage.jsp");
  243. }
  244.  
  245. package controller;
  246.  
  247. import java.io.File;
  248. import java.util.Date;
  249. import java.util.List;
  250. import model.Client;
  251. import model.Orders;
  252. import model.RentObject;
  253. import model.Staff;
  254. import org.hibernate.*;
  255. import org.hibernate.cfg.*;
  256.  
  257. public class ForClient {
  258.  
  259. public SessionFactory sessionFactory = null;
  260.  
  261. void initSession(){
  262. if (sessionFactory== null)
  263. sessionFactory = new Configuration().configure(new File("C:\Users\Маклай\Documents\NetBeansProjects\Manyezh\src\java\hibernate.cfg.xml")).buildSessionFactory();
  264.  
  265. }
  266.  
  267. public void registry(String companyName,String companyAddress,String position,String firstName,String surname,String patronymic,String tel,String email,String login,String password) {
  268.  
  269. this.initSession();
  270.  
  271. Session session = sessionFactory.openSession();
  272. session.beginTransaction();
  273.  
  274. Client cl = new Client();
  275. cl.setCompanyName(companyName);
  276. cl.setCompanyAddress(companyAddress);
  277. cl.setPosition(position);
  278. cl.setFirstName(firstName);
  279. cl.setSurname(surname);
  280. cl.setPatronymic(patronymic);
  281. cl.setTel(tel);
  282. cl.setEmail(email);
  283. cl.setLogin(login);
  284. cl.setPassword(password);
  285.  
  286.  
  287. session.save(cl);
  288. session.getTransaction().commit();
  289. session.close();
  290. }
Add Comment
Please, Sign In to add comment