File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Hashtable and vector Problem in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Hashtable and vector Problem in Servlet" Watch "Hashtable and vector Problem in Servlet" New topic
Author

Hashtable and vector Problem in Servlet

venu chow
Greenhorn

Joined: Apr 29, 2006
Posts: 5
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

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 ]

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
venu chow
Greenhorn

Joined: Apr 29, 2006
Posts: 5
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

Joined: Mar 06, 2001
Posts: 13459

check your imports in your servlet, I suspect you're importing the wrong Hashtable class.
venu chow
Greenhorn

Joined: Apr 29, 2006
Posts: 5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashtable and vector Problem in Servlet