Hi ,
I have a database which has the column "quantity available". I write a servlet(In the
doGet method), i retrieve all values and show it and I want to dynamically generate a
text box for every row in the database so the user could enter "quantity purchased".
If I dynamically generate text boxes, I need to give some name to it so I used the
priamry key column from the database to do this.I am posting the doGet method.I also
use two more files "JDBCList.java" to make connection etc and "List.java" to return
and object type of the 4 columns in database. If you want I can send code for these
two files.
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
String title = "Here is the list of products available for purchase";
response.setContentType("text/html");
out = response.getWriter();
ServletIO thisIO = new ServletIO(out);
thisIO.printTitle(title);
try {
Connection conn = JDBCList.makeConnection();
JDBCList app = new JDBCList(conn);
Object[] allprod = app.retrieveAll();
/* retrievAll retrieves the 4 columns from Database ie the primary key(product id) the
description, the price and quntity available(QA) with the Help of List class*/
HTMLForm html=new HTMLForm(request.getContextPath() +
"/servlet/JDBCListServlet");
out.println("<FORM>");
out.println("<table border=2 cellpadding=10>");
for (int i=0; i<allprod.length;i++) {
out.println("<tr>");
String name1=((List)allprod[i]).getID();
String n="";
out.println("<td>" + ((List)allprod[i]).getID());
out.println("<td>" + ((List)allprod[i]).getDescription());
out.println("<td>");
thisIO.printTextInput(n,name1);
//this is method which makes the text input box with title as the first
parameter and name of the text box as seconf paramter
out.println("<td>" + ((List)allprod[i]).getPrice());
out.println("<td>" + ((List)allprod[i]).getQA());
out.println("</tr>");
} //for i
out.println("</table>");
out.println("</table>");
out.println("</form>");
html.addSubmitButton("Purchase","submit");
thisIO.println(html.toString());
//remove the connection from the underlying class
//for added safety
app.removeConnection();
//close the connection to return it to the
//connection pool if one exists
conn.close();
thisIO.println("removed");
}//try
catch (Exception e) {
thisIO.println("Error - " + e);
}//catch
Thanks a lot for your time
Gayathri
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html