This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Retrieving hashtable values in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Retrieving hashtable values in JSP" Watch "Retrieving hashtable values in JSP" New topic
Author

Retrieving hashtable values in JSP

Shuaib Gill
Ranch Hand

Joined: May 29, 2001
Posts: 62
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...


programmer77
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Retrieving hashtable values in JSP
 
Similar Threads
javabean problem
javabean problem
Problem using Java Beans
JPA - Hibernate - query.getResultList() returns 3 null values.
Database values in JSP page