Win a copy of High Performance Python for Data Analytics this week in the Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Hashtable and vector Problem in Servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 40403
821
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic