Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Distinct names for multiple buttons

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys,

I have been working on a shopping site. i need to create different number of buttons in the jsp page according to the database.

this is my code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<%@ page import="java.sql.*" %>
<%@ page import="*" %>
<script language="javascript">


try {

String connectionURL = "jdbc:mysql://localhost:3306/login";
Connection connection = null;
Statement statement = null;
ResultSet rs= null;
connection = DriverManager.getConnection(connectionURL, "root", "root");
statement = connection.createStatement();
String QueryString = "SELECT * from revolvingchair";
rs = statement.executeQuery(QueryString);
String s[];
int i=10;
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<th>Item ID</th> <th>Item Name</th> <th>Item Description</th> <th>Item Price</th> <th>Item Available</th> <th>Quantity</th>

while ( {
<TD><input name="<% rs.getString(2);%>" type="submit" value="AddtoCart" /></TD></TR>
<% i++;
} %>
} catch (Exception ex) {

out.println("Unable to connect to database.");

<input type="submit" value="Add" name="AddtoCart" ></input>




My particular problem is i cannot differentiate the buttons when the user clicks the name wich i have given is taking as null please help me how to declare distinct names to buttons
Posts: 1845
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its been said many times before.
Scriptlet code in a JSP is bad
Database connections in a JSP is worse.

The Database code should be in a bean.
It should run the query, and convert the results into a List of java objects.
Your JSP should receive that List of objects and display it appropriately.

I don't see a form on your page. What are you submitting and to where?

In order to distinguish which button is pressed you need to give each button a distinct value. Or search for each button by name (the former being preferable)

I would suggest doing it as a link:

and then in the addToCart servlet handling this request:

request.getParameter("item") would tell you the id of the item you are wanting to add.

I don't always make ads but when I do they're tiny
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic