Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- <link rel="stylesheet" href="css/style.css">
- </head>
- <body>
- <header>
- <div class='acLogo'>
- <p>Легкоатлетичний манеж </p>
- <p class="uabs">УАБС НБУ</p>
- </div>
- <a href="ManyezhGallery.jsp" class="button1">Галерея</a>
- <a href="ManyezhRentObjectPage.jsp" class="button1">Вартість</a>
- <a href="ManyezhContactInformation.jsp" class="button1">Контактна інформація</a>
- <form action="ControllerServlet" method="post">
- <% Object isAdmin1 = request.getSession().getAttribute("isAdmin");
- if (isAdmin1 != null) {
- Boolean isAdmin = (Boolean)isAdmin1 ;
- if (isAdmin) {
- %>
- <input type="submit" value="Сторінка адміністратора" name="goToAdminPage" />
- <% }
- }
- %>
- <% Object isClient1 = request.getSession().getAttribute("isClient");
- if (isClient1 != null) {
- Boolean isClient = (Boolean)isClient1 ;
- if (isClient) {
- %>
- <input type="submit" value="Зробити замовлення" name="goToOrders" />
- <% }
- }
- %>
- <% if (isAdmin1 == null && isClient1 == null) { %>
- <div class="logIn">
- <input type="text" name="login1" placeholder='login'/>
- <input type="password" name="password1" placeholder='password'/>
- <input type="submit" value="Вхід" name="goToAccount"/>
- <input type="submit" value="Реєстрація" name="goToRegistrationPage"/>
- </div>
- <%
- }
- %>
- </form>
- </header>
- <h1>Сторінка Реєстрації</h1>
- <form class="registerPage" action="ControllerServlet" method="post">
- <table>
- <p>Назва компанії</p>
- <input type="text" name="companyName" />
- <p>Адреса компанії</p>
- <input type="text" name="companyAddress" />
- <p>Посада</p>
- <input type="text" name="position"/>
- <p>Ім'я</p>
- <input type="text" name="firstname" />
- <p>Прізвище</p>
- <input type="text" name="surname" />
- <p>По батькові</p>
- <input type="text" name="patronymic"/>
- <p>Ваш мобільний</p>
- <input type="text" name="tel"/>
- <p>Електронна пошта</p>
- <input type="text" name="email"/>
- <p>Логін</p>
- <input type="text" name="login"/>
- <p>Пароль</p>
- <input type="text" name="password"/>
- <input class='btn' type="submit" name="toDoRegistration" value="Зареєструватися"/>
- <a id="copyright" href="/Manyezh/StartPage.jsp"> На головну </a>
- </form>
- </body>
- </html>
- package controller;
- import java.io.IOException;
- import java.sql.Connection;
- import java.util.Date;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import model.Client;
- import model.Orders;
- import model.RentObject;
- public class ControllerServlet extends HttpServlet {
- private static Connection connect;
- private static final String url = "jdbc:oracle:thin:@localhost:1521:orcl";
- private static final String userName = "system";
- private static final String mypassword = "blink1994";
- private static final String className ="oracle.jdbc.driver.OracleDriver";
- /**
- * 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
- */
- @Override
- public void init() throws ServletException {
- try {
- super.init();
- Class.forName(className);
- try {
- connect = DriverManager.getConnection(url,userName, mypassword);
- } catch (SQLException ex) {
- Logger.getLogger(JDBC_Servlet.class.getName()).log(Level.INFO, null, ex);
- }
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(JDBC_Servlet.class.getName()).log(Level.INFO, null, ex);
- }
- }
- // <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 {
- }
- /**
- * 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 {
- ForClient forClient = new ForClient();
- ForAdmin forAdmin = new ForAdmin();
- String buttonGoToRegistrationPage = request.getParameter("goToRegistrationPage");
- String buttonToDoRegistration = request.getParameter("toDoRegistration");
- String buttonGoToAccount = request.getParameter("goToAccount");
- String buttonGoToGallery = request.getParameter("goToPhoto");
- String buttonGoToAdminPage = request.getParameter("goToAdminPage");
- String buttonToDoOrder = request.getParameter("toDoOrder");
- String buttonSubmitOrder = request.getParameter("SubmitOrder");
- String goToOrders = request.getParameter("goToOrders");
- String buttonClientInfo = request.getParameter("ClientInfo");
- String deleteOrder = request.getParameter("deleteOrder");
- String ChangeBtn = request.getParameter("Change");
- String ChangeOrder = request.getParameter("ChangeOrder");
- String toCost = request.getParameter("toCost");
- if (goToOrders != null){
- List<RentObject> rentObj = forClient.dropDownList();
- request.getSession().setAttribute("rentObj", rentObj);
- response.sendRedirect("OrderPage.jsp");
- }
- if (buttonGoToRegistrationPage != null){
- response.sendRedirect("Registration.jsp");
- }
- if (buttonToDoRegistration != null){
- String companyName = request.getParameter("companyName");
- String companyAddress = request.getParameter("companyAddress");
- String position = request.getParameter("position");
- String firstName = request.getParameter("firstname");
- String surname = request.getParameter("surname");
- String patronymic = request.getParameter("patronymic");
- String tel = request.getParameter("tel");
- String email = request.getParameter("email");
- String login = request.getParameter("login");
- String password = request.getParameter("password");
- forClient.registry(companyName,companyAddress,position,firstName,surname, patronymic,tel,email,login,password);
- response.sendRedirect("StartPage.jsp");
- }
- package controller;
- import java.io.File;
- import java.util.Date;
- import java.util.List;
- import model.Client;
- import model.Orders;
- import model.RentObject;
- import model.Staff;
- import org.hibernate.*;
- import org.hibernate.cfg.*;
- public class ForClient {
- public SessionFactory sessionFactory = null;
- void initSession(){
- if (sessionFactory== null)
- sessionFactory = new Configuration().configure(new File("C:\Users\Маклай\Documents\NetBeansProjects\Manyezh\src\java\hibernate.cfg.xml")).buildSessionFactory();
- }
- public void registry(String companyName,String companyAddress,String position,String firstName,String surname,String patronymic,String tel,String email,String login,String password) {
- this.initSession();
- Session session = sessionFactory.openSession();
- session.beginTransaction();
- Client cl = new Client();
- cl.setCompanyName(companyName);
- cl.setCompanyAddress(companyAddress);
- cl.setPosition(position);
- cl.setFirstName(firstName);
- cl.setSurname(surname);
- cl.setPatronymic(patronymic);
- cl.setTel(tel);
- cl.setEmail(email);
- cl.setLogin(login);
- cl.setPassword(password);
- session.save(cl);
- session.getTransaction().commit();
- session.close();
- }
Add Comment
Please, Sign In to add comment