Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I Modify your LoginServlet . Using the Customer Business Object that we built in Lab #5, change the Login Servlet to get the pw

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 Accounts 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 GET and POST * 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
");

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 "); 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 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions