Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part I – Modify your LoginServlet . Using the Customer Business Object that we b

ID: 3591825 • Letter: P

Question

Part I – Modify your LoginServlet. Using the Customer Business Object that we built in Lab #5, change the Login Servlet to get the pw from the Database and check that against the password the User enters in the HTML Gui.

Part II – Modify your LoginServlet. Use the requestDispatcher to forward control onto an Error Page (“ErrorPage.jsp”), if the user login is not correct.

Part III – Modify your LoginServlet again. Again use the requestDispatcher to forward control onto an AccountLookup page (“AccountLookup.jsp”), if the user login is correct. We created the AccountLookup.jsp back in Lab #1.

Part IV – Next, in your “LoginServlet”, put the Customer object in the Session. This Customer object will be used by a later Servlet to display customer info.

Part V – Now build the AccountLookupServlet. This servlet should read the input from the previous HTML file and Find the Account’s information from the database, using the Account business class, then display the information back to the “Server Log”. The AccountLookupServlet should be scheduled when the user clicks on the Retrieve button from the “Account. Note: The AccounLookupServlet will not generate any HTML code. That will be done in the next Lab.

w

Part VI – Lastly, in your “AccountLookupServlet”, put the Account object in the Session. This Account object will be used by a later Servlet to display Account info.

I need the modified login servlet and accountlookup servlet and accountlookup .jsp with error.jsp

login servlet is this

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

/**
* 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
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("LoginServlet Running…<br></br>");

String id = request.getParameter("id");
String pass = request.getParameter("password");

  
try {
if (checkUser(id, pass)) {
out.println("Valid Login");
RequestDispatcher rs = request.getRequestDispatcher("welcome.html");
rs.forward(request, response);
} else {
out.println("InValid Login<br>");
RequestDispatcher rs = request.getRequestDispatcher("Login.html");
rs.include(request, response);
}
} catch (SQLException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
}

}
}

/**
* Handles the user validation method.
*
* @param id String user id request
* @param pass user password request
* @return true if valid user, otherwise false
* @throws java.sql.SQLException
* @throws java.lang.ClassNotFoundException
*/
  
public static boolean checkUser(String id, String pass) throws SQLException ,ClassNotFoundException{
boolean valid = false;
{
//loading drivers for mysql
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:ChattBankMDB");
String Username = "Admin";
String Password="123";
String Url="jdbc:ucanaccess://localhost:3306/Admin";
  
con = DriverManager.getConnection(Url, Username, Password);
String query ="select*from customers";
Statement stmt = con.createStatement();
ResultSet rs = null;
  
  
String u,p;
while (rs.next())
{
u=rs.getString(1);
p=rs.getString(2);
  
valid = true;
break;
}//End of if statement
}//End of while loop
return valid;
}//End of method check user
}

Explanation / Answer

For AccountLookupServlet, previous HTML File and Account buisness object is required. If you have these both, then you can create the servlet the same way as LoginServlet. For Part 3, As you are already having AccountLookup.jsp(As mentioned in question), control will be forwarded to AccountLookup.jsp.

Let me know if you have any further queries.

  Please find below the modified LoginServlet.java and ErrorPge.jsp for Part 1 to 4.  Comments are added for each part wherever necessary.    LoginServlet.java          import java.io.IOException;  import java.io.PrintWriter;  import java.sql.Connection;  import java.sql.DriverManager;  import java.sql.ResultSet;  import java.sql.SQLException;  import java.sql.Statement;  import java.util.logging.Level;  import java.util.logging.Logger;  import javax.servlet.RequestDispatcher;  import javax.servlet.ServletException;  import javax.servlet.http.HttpServlet;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse;  public class LoginServlet extends HttpServlet {      /**       * 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       */      protected void processRequest(HttpServletRequest request, HttpServletResponse response)              throws ServletException, IOException {          response.setContentType("text/html;charset=UTF-8");          try (PrintWriter out = response.getWriter()) {              out.println("LoginServlet Running…<br></br>");              String id = request.getParameter("id");              String pass = request.getParameter("password");                            try {                  if (checkUser(id, pass)) {                     // out.println("Valid Login");                   /*----------------------  Part 4 ----------------------------------------*/                  Customer customer=new Customer();                    //Create customer object if valid Id and psssword                  customer.setId(id);                  customer.setPassword(pass);                                                        HttpSession session=request.getSession();                        //Set customer object in session                       session.setAttribute("customer",customer);                                               /*----------------------  Part 3 ----------------------------------------*/                      RequestDispatcher rs = request.getRequestDispatcher("AccountLookup.jsp");                      rs.forward(request, response);                  } else {                    //  out.println("InValid Login<br>");                   /*----------------------  Part 2 -----------------------------------------*/                      RequestDispatcher rs = request.getRequestDispatcher("ErrorPage.jsp");                      rs.include(request, response);                  }              } catch (SQLException ex) {                  Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);              } catch (ClassNotFoundException ex) {                  Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);              }          }      }       /**       * Handles the user validation method.       *       * @param id String user id request       * @param pass user password request       * @return true if valid user, otherwise false       * @throws java.sql.SQLException       * @throws java.lang.ClassNotFoundException       */          public static boolean checkUser(String id, String pass) throws SQLException ,ClassNotFoundException{          boolean valid = false;          {              //loading drivers for mysql              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");              Connection con = DriverManager.getConnection("jdbc:odbc:ChattBankMDB");              String Username = "Admin";              String Password="123";              String Url="jdbc:ucanaccess://localhost:3306/Admin";                            con = DriverManager.getConnection(Url, Username, Password);              String query ="select*from customers";              Statement stmt = con.createStatement();              ResultSet rs = null;               rs = stmt.executeQuery(query);                                            String u,p;                      while (rs.next())                      {                          u=rs.getString(1);                          p=rs.getString(2);                        /*--------------Part 1--------------------*/                            if(id.equals(u) && pass.equals(p)){                                   valid = true;    //If ID and password match, then set valid to true.                               break;                          }                                               }//End of if statement          }//End of while loop          return valid;      }//End of method check user  }                            ErrorPage.jsp         <%@ page language="java"         contentType="text/html; charset=windows-1256"        pageEncoding="windows-1256"     %>       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"            "http://www.w3.org/TR/html4/loose.dtd">       <html>          <head>           <meta http-equiv="Content-Type"               content="text/html; charset=windows-1256">           <title>Invalid Login</title>        </head>          <body>           <center>              Invalid Username or Password           </center>        </body>     </html>  

For AccountLookupServlet, previous HTML File and Account buisness object is required. If you have these both, then you can create the servlet the same way as LoginServlet. For Part 3, As you are already having AccountLookup.jsp(As mentioned in question), control will be forwarded to AccountLookup.jsp.

Let me know if you have any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote