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 Java in General and the fly likes TypeCast from String to HashMap 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 » Java in General
Reply Bookmark "TypeCast from String to HashMap" Watch "TypeCast from String to HashMap" New topic
Author

TypeCast from String to HashMap

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Hi friends,

I have a HashMap in my jsp page and i put it in the hidden field and pass it back to Controller. But when i try to cast to back to HashMap its showing some error stating that "Cannot cast from String to HashMap".

The code snippet is :


Is there a way to do this. Because its easy for me to use HashMap and i'm passing this throughout the film ticket booking cycle. Please guys help me get out of this issue.

Thanks in advance.


Never try to be a hard-worker. Be a smart-worker.
My Blog
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
The method getParameter always returns a String, no way out.

If your HashMap already exists before the jsp, just put it in a request or session attribute before calling the jsp and get i back as a request or session attribute.

If you want to build a new hashmap with key-value pairs taken from input fields, you could just get them as request parameters and build the new hashmap.

Just as an example:





Bye,
Nicola
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TypeCast from String to HashMap
 
Similar Threads
Class Cast Exception while reading the int value from a session object
Generics question
Create Immutable HashMap
Retrieving Data from HashMap
string[] modification