Answered You can hire a professional tutor to get the answer.
Part A - Modify your The old LoginServlet passed control to an HTML file called AccountLookup.html. Change this. Have the LoginServlet pass control to different JSP, called "". Part B - Now build th
Part A - Modify your The old LoginServlet passed control to an HTML file called AccountLookup.html. Change this. Have the LoginServlet pass control to different JSP, called "".
Part B - Now build the file. This file will be different than the AccountLookup.jsp that we built in Lab #6. This JSP should get the Customer object out of the Session. This Customer Object should contain the AccountList object that holds a list of Accounts. Then using scriptlet tags, display a table of accounts for this customer.
AccountServlet.java
package com.ChattBank.controller;
import com.ChattBank.business.Account;
import com.ChattBank.business.Accounts;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
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 javax.servlet.http.HttpSession;
public class AccountServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("");
out.println("");
out.println("");
out.println("Servlet AccountServlet");
out.println("");
out.println("");
out.println("Servlet AccountServlet at " + request.getContextPath() + "");
out.println("");
out.println("");
}
}
//
/** HTTP method */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//HttpSession session = request.getSession();
String action = request.getParameter("action");
if (action == null) {
request.getRequestDispatcher("/Welcome.jsp").forward(request, response);
} else if (action.equals("view")) {
Accounts acct = new Accounts();
ArrayList list = new ArrayList();
try {
acct.setCustAccounts(request.getParameter("id"));
list.addAll(acct.getCustAccounts());
System.out.println(request.getParameter("id"));
//This was moved into the try block itself
request.setAttribute("acctList", list);
request.getServletContext().getRequestDispatcher("/accounts.jsp").forward(request, response);
} catch (SQLException ex) {
Logger.getLogger(Accounts.class.getName()).log(Level.SEVERE, null, ex);
//This is the added finally statement with the clearAccounts method
} finally {
acct.clearAccounts();
}
}
}
/** HTTP POST method */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
String custId = request.getParameter("custID");
if (action == null) {
request.getRequestDispatcher("/Welcome.jsp").forward(request, response);
}
}
/** Returns a short description of the servlet */
@Override
public String getServletInfo() {
return "Short description";
}//
}
accounts.jsp
--%>
Your Accounts
ArrayList list = new ArrayList();
list.addAll((ArrayList)request.getAttribute("acctList"));
for (Account custAccount : list) {
System.out.println("From JSP: " + custAccount.getCustId() + " " + custAccount.getAcctNo() + " " + custAccount.getAcctType() + " " + custAccount.getBalance());
System.out.println("Getting Object From Section");
}
%>
Done
Your Chatt Accounts
Account:
Thank you for your business!