Hi guys
Actually I am adding a integer to my vector which is coming as a
parameter from the url but what I want is to show the same vector on
the same page but what problem I'm facing is it is showing me only one
element in the vector even if I add a lot of data to my vector pls tell
me what cld be the problem :
my code is as follows :
dis.jsp:----
<%@page language=3D"java" import=3D"java.util.*"%>
<%@page import=3D"shop.disBean"%>
<%@page import=3D"shop.cart"%>
<HTML>
<HEAD>
<TITLE>
Display Products
</TITLE>
</HEAD>
<BODY topmargin=3D"0" leftmargin=3D"0">
<table cellspacing=3D"2" cellpadding=3D"2" border=3D"1">
<tr>
List of Book
<table border=3D"3">
<tr>
<td>Book Name</td>
<td>Price</td>
<td>Publisher</td>
<td>CD</td>
<td>Category Name</td>
<td>Buy</td>
</tr>
<%--int ibook_id;--%>
<% Vector vect=3Dnew Vector();
Vector add =3D new Vector();
cart newcart =3D new cart();
disBean disB=3Dnew disBean();
disB.connect();
vect=3DdisB.query();
int size=3Dvect.size();
for(int i=3D0;i<size;i++)
{
Object refObj=3Dvect.elementAt(i);
disBean strRecord=3D(disBean) refObj;
%>
<tr>
<td><%=3D strRecord.getBook_name()%></a></td>
<td><%=3D strRecord.getPrice()%></td>
<td><%=3D strRecord.getPublisher() %></td>
<td><%=3D strRecord.getCd() %></td>
<td><%=3D strRecord.getCategory_name() %></td>
<td><a href=3D"dis.jsp?book_id=3D<%=3DstrRecord.getBook_id()%>">add to
cart</a></td>
</tr>
<%
}%>
</table>
</td></tr></table>
<%
String s =3D request.getParameter("book_id");
int BookId;
if (s !=3D null )
{
BookId =3D Integer.parseInt(s);
out.println("Id u chossed is " + BookId);
add =3D newcart.addtocart(BookId);
%>
<%
}
%>
<%
int addsize =3D add.size();
if (addsize > 0)
{
for(int i=3D0; i<addsize;i++)
{
int bookid =3D
((Integer)add.elementAt(i)).intValue();
%>
<%=3Dbookid%> <br>
<%
}}%>
</BODY>
</HTML>
and my bean is as following through this bean only I'm adding elements
in the vector
package shop;
import java.util.*;
import java.sql.*;
public class cart extends disBean{
Vector list =3D new Vector();
int size;
Connection conn;
String url =3D "jdbc:odbc:test";
public Vector addtocart(int id)
{
if(id > 0)
{
list.addElement(new Integer(id));
}
return list;
}
public int getSize()
{
int size =3D list.size();
return size;
}
/* public void showcart()
{
int len =3D list.size();
for(int i=3D0;i<len;i++)
{
System.out.println(list.elementAt(i));
}
}*/
public boolean getDetails(int bookid)throws SQLException,
ClassNotFoundException{
try
{
conn =3D DriverManager.getConnection(url, "sa", "");
Statement stmt =3D conn.createStatement();
String query =3D " select b.book_id, b.book_name,
b.price,"+
"b.publisher, b.cd, c.category_name from book b, category
c"+
"where b.category_id =3D c.category_id and "+
"b.book_id =3D " + bookid ;
// here we try to find the details of the book specified by the
book_id
file://of this object
ResultSet rs =3D stmt.executeQuery(query);
while (rs.next())
{
setBook_id(rs.getInt("book_id"));
setBook_name(rs.getString("book_name"));
setPrice(rs.getInt("price"));
setPublisher(rs.getString("publisher"));
setCd(rs.getString("cd"));
setCategory_name(rs.getString("category_name"));
}
stmt.close();
conn.close();
return true;
}//end of try
catch (SQLException e) {
conn.close();
return false;
}
}
public void empty(Vector vect)
{
vect.removeAllElements();
}
}
pls help me out I know the problem is in the vector ..
any help wld be great
Thanks in advance
Regards Preeti