• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Retrieving hashtable values in JSP

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a servlet which stores values of a database field in a Java Bean hashtable. This hashtable then needs to output the specific values of the hashtable in a JSP. I am having problems retrieiving these values. I have used an 'Object' to store the results of the retrieval in the Bean, but I cannot get the right output in my JSP. Any help is appreciated. Here are codde snipplets....
// my servlet, which stores values in Java Bean and then calls // JSP
NotesBean notesData=new NotesBean();
int i=0;
while(rs.next())
{
getServletContext().setAttribute("notesData",notesData);


notesData.setFname (rs.getString("fname"));
notesData.setLname (rs.getString("lname"));
notesData.setAge (rs.getInt ("age"));
notesData.setPut( i, rs.getString("fname"));
i++;
}

rs.close();

RequestDispatcher notesRd=
getServletConfig().getServletContext().getRequestDispatcher(notesView);
req.getRequestDispatcher(notesView);
notesRd.forward(req,res);
// Java Bean
package dcx.salesAndMarketingOperations;
import java.io.*;
import java.util.*;
import java.lang.Integer;
public class NotesBean// JavaBeans example
{
private String fname;
private Object valueOfFname;
private String fnameAsString;
private String notesHT;
private String lname;
private int age;
private int i;
private int size;
private Hashtable notesHashtable = new Hashtable();
public void setFname (String fname)
{
this.fname=fname;
}
public void setLname (String lname)
{
this.lname=lname;
}
public void setAge (int age)
{
this.age=age;
}
public void setPut( int i, String fname )
{
this.fname=fname;
valueOfFname=null;
notesHashtable.put(new Integer(i),fname);

size=notesHashtable.size();
valueOfFname=notesHashtable.get(new Integer(i));
fnameAsString=(String)valueOfFname.toString()
}
public void setSize()
{
size=notesHashtable.size();
}
public String getFname()
{
return fname;
}
public String getLname()
{
return lname;
}
public int getAge()
{
return age;
}
public String getPut()
{
return fnameAsString;//notesHT;
}
public int getSize()
{
return size;
}

}
// my JSP snipplet which needs to see all values of hastable in // drop down list
<form method="get">
<select name="whichNote" size="5" width="10">
<br>
<%! int j=0; %>
<% while(j< 7) { %>
<option value="notesDescription">
<%= notesData.getPut() %>
<% j++; } %>
</select>
<br>
<input type="submit">
</form>
Hope you can help...
 
It's feeding time! Give me the food you were going to give to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic