Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a<%--
- Document : Loginconfirmation
- Created on : Apr 28, 2017, 6:04:57 PM
- Author : Ryuji
- --%>
- <%@page import="java.sql.ResultSet"%>
- <%@page import="java.sql.Statement"%>
- <%@page import="java.sql.DriverManager"%>
- <%@page import="java.sql.Connection"%>
- <%@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>
- <%
- boolean checkLogin = false;
- String status = "";
- String UserID = request.getParameter("UserID");
- String Password = request.getParameter("Password");
- Connection connection = null;
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- String url = "jdbc:mysql://localhost/dbsterling";
- String user = "root";
- String pwd = "";
- connection = DriverManager.getConnection(url, user, pwd);
- Statement statement = connection.createStatement();
- String querySelect = "select * from sterling_login, sterling_customer, sterling_employee where sterling_login.UserID = sterling_customer.UserID && sterling_login.UserID = sterling_employee.UserID && sterling_login.UserID = '" + UserID + "'";
- ResultSet rows = statement.executeQuery(querySelect);
- while (rows.next()) {
- if((rows.getString("sterling_customer.UserID") == UserID) && (rows.getString("sterling_login.Password") == Password)) {
- checkLogin = true;
- status = "Customer";
- }
- else if((rows.getString("sterling_employee.UserID") == UserID) && (rows.getString("sterling_employee.Designation") == "M") && (rows.getString("sterling_login.Password") == Password)) {
- checkLogin = true;
- status = "Manager";
- }
- else if((rows.getString("sterling_employee.UserID") == UserID) && (rows.getString("sterling_employee.Designation") == "C") && (rows.getString("sterling_login.Password") == Password)) {
- checkLogin = true;
- status = "Clerk";
- }
- else if((rows.getString("sterling_employee.UserID") == UserID) && (rows.getString("sterling_employee.Designation") == "D") && (rows.getString("sterling_login.Password") == Password)) {
- checkLogin = true;
- status = "DeliveryBoy";
- }
- else
- out.println("<script>alert('Login credention does not exist!!! ');document.location.href='Login.jsp';</script>");
- }
- if(checkLogin = true) {
- session.setAttribute("UserID", UserID);
- session.setAttribute("Status", status);
- response.sendRedirect("home.html");
- }
- else
- out.println("<script>alert('Login!!! ');document.location.href='Login.jsp';</script>");
- }
- catch (Exception e) {
- out.println("Error" + e);
- System.out.println("Error" + e);
- //It is a good practice to use System.out.println()
- //for printing the error messages in the server console
- }
- finally {
- if (null != connection) {
- connection.close();
- }
- }
- %>
- </head>
- <body>
- <h1>Hello World!</h1>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement