Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashtable and vector Problem in Servlet

 
venu chow
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem...

In my servlet I created a vector

Vector vec = new Vector();
Hastable hash = new Hashtable();
hash.put("hai",hai);
vec.addElement("bye");
vec.addElement("50");
vec.addElement(hash);


Now When i get the Vector in the Jsp..
I get the values by using
Vector vec = request.getAttribute("vec");

Now I want to store my Hashtable variable hash into a hashtable in the JSP
like
Hashtable hash = (Hashtable)vec.elementAt(1);

But this line is throwing an exception please could any one help me out

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venu,
Double checking the indexes:
vec.addElement("bye"); // index 0
vec.addElement("50"); // index 1
vec.addElement(hash); // index 2

So the JSP should be getting the element with index 2 before casting to HashTable.

[edited to fix typo]
[ April 29, 2006: Message edited by: Jeanne Boyarsky ]
 
venu chow
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks but ya I set the attribute using
req.setAttribute("vec",vec);
I got the remaining two values using vec.elementAt(0) and vec.elementAt(1)
But am getting an eception when I use

Hashtable hash = new Hashtable();
hash = (Hashtable)tempresult.elementAt(2);

Here I am getting an exception..
ava.lang.ClassCastException: com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable
org.apache.jsp.datamart.screen3_jsp._jspService(screen3_jsp.java:222)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
code.Results.doPost(Results.java:108)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Please could u help me out
Thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check your imports in your servlet, I suspect you're importing the wrong Hashtable class.
 
venu chow
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dude It worked there was some other class imported
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;

So it was not working..
Thanks once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic