Menu

[solved]-Need Help Figuring Parts Project Current Code Follow Part Iv Chattbank Modify Accountlook Q39072520

I need some help figuring out these parts to my project. Mycurrent code will follow below.

Part IV Again in ChattBank,modify your AccountLookupServlet from Lab #6. YourAccounLookupServlet should:

  1. Read the AccountNo from the previous HTML page.
  2. Use the AccountNo to Create a Business Object that gets theAccount info from the database.
  3. Put this Business Object in the Session and
  4. Forward control to the “DisplayAccount.jsp”.

Part V Now build the“DisplayAccount.jsp”. The HTML code in this file will be exactlythe same as in the “AccountLookup.jsp. You can copy the HTML code.The difference is that this jsp will get the Account object out ofthe Session and display the Account info in the appropriatetextboxes(input types).

accountLookup.JSP same as display JSP code

<%@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>
</head>
  
<form action=”http://localhost:8080/ChatBank/display.jsp”method=”post”>
  
<form>
<h1>Account Lookup</h1> <br>
<table border=”3″>
<tr>
<td>
<input type=”text” name=”acctb” value=”AccountNumber”/>
</td>
</tr>
<tr>
<td>
<input type=”text” name=”custidtb” value=”CustomerID”/>
</td>
</tr>
<tr>
<td>
<input type=”text” name=”typetb” value=”Account Type”/>
</td>
</tr>
<tr>
<td>
<input type=”text” name=”balancetb” value=”Balance”/>
</td>
</tr>
<tr>
<td>
<input type=”submit” value=”Lookup”/>
</td>
</tr>
<tr>
<td>
<input type=”reset” value=”Clear”/>
</td>
</tr>
</table>
</form>
</html>

accountBusinessObject

package Business;
import java.sql.*;
public class Account
{
private int acctno;
private int cid;
private String type;
private int balance;
private int withdraw;
private int amount;
  
public Account()
{
acctno = 0;
cid = 0;
type = “”;
balance = 0;
withdraw = 0;
}
  
public Account(int acn, int id, String ty, int bl, int wd, intamount)
{
acctno = acn;
cid = id;
type = ty;
balance = amount;
withdraw = wd;
// deposit = dps;
}
  
public void selectDB(int acn)
{
acctno = acn;
try
{
Class.forName(“net.ucanaccess.jdbc.UcanaccessDriver”);
Connection c1;
c1 =DriverManager.getConnection(“jdbc:ucanaccess://c:/Users/brand/source/repos/ChattBankACCDB.accdb”);
  
Statement stmt = c1.createStatement();
ResultSet rs = stmt.executeQuery(“Select * from Accounts whereAcctNo = ‘”+ acn + “‘”);
  
rs.next();
cid = rs.getInt(2);
type = rs.getString(3);
balance = rs.getInt(4);
  
c1.close();
}
  
catch(Exception se)
{
System.out.println(se);
}
}
  
public int getacctno()
{
return acctno;
}
public void setacctno(int acn)
{
acctno = acn;
}
  
public int getcid()
{
return cid;
}
public void setcid(int id)
{
cid = id;
}
  
public String gettype()
{
return type;
}
public void settype(String ty)
{
type = ty;
}
  
public int getbalance()
{
return balance;
}
public void setbalance(int bl)
{
balance = bl;
}
  
public int getamount()
{
return amount;
}
  
  
public void display()
{
System.out.println(“Account Number = ” + acctno);
System.out.println(“Cid = ” + cid);
System.out.println(“Type = ” + type);
System.out.println(“Balance = ” + balance);
  
}
  
public static void main(String args[])
{
Account a1;
a1 = new Account();
a1.selectDB(55555);
a1.deposit(0);
a1.withdraw(0);
a1.display();
}
  
private void deposit(int amount)
{
balance = balance + amount;
}
  
public void withdraw(int amount)
{
balance = balance – amount;
}

}

accountLookupServlet

import Business.Account;
import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.System.out;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet(urlPatterns = {“/AccountLookupServlet”})

public class AccountLookupServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType(“text/html;charset=UTF-8”);
  
String acn;
  
try (PrintWriter out = response.getWriter())
{
acn = request.getParameter(“acctb”);
System.out.println(“Account Number Recieved = ” + acn);
  

//HttpSession ses1;
//ses1 = request.getSession();
//Account a1;
//a1 = (Account)ses1.getAttribute(“c1”);
//System.out.println(“Account retrieved from Session…”);
//a1.display();

Account a1;
a1 = new Account();
a1.selectDB(Integer.parseInt(acn));
a1.display();

RequestDispatcher rd =request.getRequestDispatcher(“display.jsp”);
rd.forward(request, response);

HttpSession ses2;
ses2 = request.getSession();
ses2.setAttribute(“a1”,a1);
  
}
  
catch(Exception e)
{
System.out.println(“Error in finding EJB”);
}
  
finally
{
System.out.println(“LoginServelt Ending”);
out.close();
}
}
  
@Override
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return “Short description”;
}

}

Expert Answer


Answer to I need some help figuring out these parts to my project. My current code will follow below. Part IV – Again in ChattBa… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *