I have to do an HTML page with 2 text boxes, one for name and the other one for ammount, then theres a widget that let me choose which type of account im creating, savings or checking, then a send button, this information is going to be sent to the servlet. The servlet have to create an object depending on the type of account, then save it on a Vector
, then the servlet need to respond an HTML textarea with the information thats on the Vector
, and the same widgets that were in the first page so you can insert another account, when you insert another one you have to send the information to the same servlet, and then do the same work. But in the HTML text area must appear the first account and the one that I just created, and so on and on.
The thing is that I can do all of this but what I can't do is the showing all the information of the vector for some reason I just get the account that I just created in the text area.
Here's the servlet code. Note, the toString()
returns all of the info thats stored on the Vector
, and addAccount()
adds the account to the Vector
.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletPrincipal extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String nombre = request.getParameter("nom");
String monto = request.getParameter("mon");
String tipo = request.getParameter("fgcghch");
double montoi = Double.parseDouble(monto);
String a="ah";
String b="che";
AccountsLedger objeto = new AccountsLedger();
if(a.equals(tipo)){
SavingsAccount cnt1= new SavingsAccount(nombre, montoi, 2);
objeto.addAccount(cnt1);
objeto.toString();
out.println("<textarea rows='20' cols='20'>"+objeto.toString()+"</textarea>");
out.print("<form action='ServletPrincipal' method='post'><input type='text' name='nom'><input type='text' name='mon'>");
out.println("<select name='fgcghch'><option value='ah'>Ahorro</option><option value='che'>Cheque</option></select>");
out.println("<input type='submit' name='boton'></form>");
}
if(b.equals(tipo)){
CheckingAccount cnt= new CheckingAccount(nombre, montoi);
objeto.addAccount(cnt);
String y = objeto.toString();
out.println("<textarea rows='2' cols='20'>"+y+"</textarea>");
out.print("<form action='ServletPrincipal' method='post'><input type='text' name='nom'><input type='text' name='mon'>");
out.println("<select name='fgcghch'><option value='ah'>Ahorro</option><option value='che'>Cheque</option></select>");
out.println("<input type='submit' name='boton'></form>");
}
}
}