aspose file tools*
The moose likes JSP and the fly likes Objects in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Objects in JSP" Watch "Objects in JSP" New topic
Author

Objects in JSP

tejaswini vasist
Greenhorn

Joined: Apr 10, 2004
Posts: 17
i have a jsp which retieves an object and displays its contentsin the page.
The servlet written wil set the object values.I hav given print statements in the servlet.The output of which is correct and shows in Tomcat.But however the jsp doesnt show the same items even though i am retieving the same object and displayin it.What could be the problem?
jsp code:
<% DisplayItems items = new DisplayItems();
int numberOfItems=0;
String value = new String();
value = (String)request.getAttribute("NUMBER");
numberOfItems = Integer.parseInt(value);
items = (com.onjava.DisplayItems)request.getAttribute("ITEMS");
System.out.println("In jsp : " +numberOfItems);
try {
for (int j=0; j<numberOfItems; j++)
{
%>



<tr>

<td bgcolor=lightsteelblue><font face="verdana, arial, helvetica" size="2" width="20%"> <%=items.ItemID[j]%> </td>
<td bgcolor=lightsteelblue><font face="verdana, arial, helvetica" size="2" width="20%"> <%=items.ItemName[j]%> </td>
<td bgcolor=lightsteelblue><font face="verdana, arial, helvetica" size="2" width="20%"> <%=items.Quantity[j]%> </td>
</tr>
servlet code:
while(i<(vectorSize))
{
intElement = Integer.parseInt(listArray[i]);
try
{
conn= ct.getConnection();
}
catch(Exception e)
{
System.out.println("connection exception");
}
try
{
query = "select ItemID, ItemName, Price, QtyRemaining from Item where ItemID = '";
query = query + vect.elementAt(i) + "'";
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
while(rs.next())
{
ItemID=rs.getInt("ItemID");
ItemName=rs.getString("ItemName");
Price=rs.getFloat("Price");
QtyRemaining=rs.getInt("QtyRemaining");
/*QtyRemaining=rs.getInt("QtyRemaining");
ThresholdQuantity=rs.getInt("ThresholdQuantity");*/
System.out.println(ItemID+"\t"+ItemName+"\t\t\t"+Price+"\t"+quantityArray[k]);
size = rs.getRow();
item.setItemID(ItemID);
item.setItemName(ItemName);
item.setPrice(Price);
item.setQuantityRemaining(QtyRemaining);
/*item.setThresholdQuantity(ThresholdQuantity);*/
dispitems.ItemID[k] = ItemID;
dispitems.ItemName[k] = ItemName;
dispitems.Quantity[k] = Integer.parseInt(quantityArray[k]);

System.out.println("***************************");
System.out.println("itemid:" + dispitems.ItemID[k]);
System.out.println("itemname:" + dispitems.ItemName[k]);
System.out.println("quant:" + dispitems.Quantity[k]);
} //end of while
the output of these print statements are correct but in jsp they show diff values.
the below code is a part of my dopost method:
DisplayItems dispitems1 = new DisplayItems();
SelectItems selitem = new SelectItems();

try
{
dispitems1 = selitem.dispSelectedItems(vect,quant);
}
catch(Exception e)
{
System.out.println("vector problem" + e.getMessage());
}


//Integer IntVal = new Integer(vectorSize1);
String str1=new String();
str1=Integer.toString(stcnt);
request.setAttribute("NUMBER", str1);
request.setAttribute("ITEMS", dispitems1);

// Forward the request to the target named
ServletContext context = getServletContext();
RequestDispatcher dispatcher =
context.getRequestDispatcher(target);
dispatcher.forward(request, response);
}
here i catch the object and convert it into response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objects in JSP
 
Similar Threads
Text Boxes and JSP
jsp - checkbox information retieval problem
Storing of Data
Calling java method on a button click?
Scrollbar for table using div doesnt work in IE