Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Objects in JSP

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Beauty is in the eye of the tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic