• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving hashtable values in JSP  RSS feed

 
Shuaib Gill
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!