Question: Part I Build a simple JSP. This JSP should be added to your TestProj project. This JSP is separate from the ChattBank App. Call it
Part I Build a simple JSP. This JSP should be added to your TestProj project. This JSP is separate from the ChattBank App. Call it Loops.jsp. The JSP should simply print out Go Braves 10 times. Use a loop to accomplish this. Run this JSP by right clicking on the JSP filename and selecting run.
Part II - Build another simple JSP. This JSP should be added to your TestProj project also. Create a JSP that outputs Hello World, but only 6 times. Each output should be in an tag, where the ?gets higher each time through the loop. (i.e.
.
..). Call this JSP Hello.jsp. Also run this JSP by right clicking on the JSP filename and selecting run.
Part III Now back to the ChattBank Project. Modify the JSP LoginError.jsp. Make it so that when the User logs in incorrectly, the LoginError page should output: Error Logging in for User with ID 3001, or whatever ID the User tries to use. You will need to get the Customer Object out of the Session and get the cid and output this to the HTML.(i.e. User with ID 3001, invalid password!! you get the user ID from the Business Object in the Session.)
Part IV Again in ChattBank, modify your AccountLookupServlet . Your AccounLookupServlet should:
Read the AccountNo from the previous HTML page.
Use the AccountNo to Create a Business Object that gets the Account info from the database.
Put this Business Object in the Session and
Forward control to the DisplayAccount.jsp.
Part V Now build the DisplayAccount.jsp. The HTML code in this file will be exactly the same as in the AccountLookup.jsp. You can copy the HTML code. The difference is that this jsp will get the Account object out of the Session and display the Account info in the appropriate textboxes(input types).
loginerror.jsp(not sure if correct,you can modify it)
<%@ page language="java" contentType="text/html; charset=windows-1256" pageEncoding="windows-1256" %>
Accountlookupservlet(incorrect,mmodify first)
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.HttpSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
/** * * @author Bosslady */
public class Accountlookupservlet 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"); /*---------------------- Part 4 ---------------------------------------*/ HttpSession session=request.getSession(); //Set customer object in session /*---------------------- Part 3 ----------------------------------------*/ RequestDispatcher rs = request.getRequestDispatcher("AccountLookup.jsp"); rs.forward(request, response); } else { // out.println("InValid Login "); /*---------------------- Part 2 -----------------------------------------*/ RequestDispatcher rs = request.getRequestDispatcher("ErrorPage.jsp"); rs.include(request, response); } } catch (SQLException ex) { Logger.getLogger(Accountlookupservlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(Accountlookupservlet.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 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
