| Author |
Cannot cast from String to ArrayList(JSP)
|
Omar Perez
Ranch Hand
Joined: Jul 08, 2011
Posts: 35
|
|
Good day,
I'm actually trying to complete the excersise of the Servlets and JSP book in page 303 but I'm getting the following error in Eclipse Cannot cast from String to ArrayList(JSP).
Here is the code
The error as it appears in line <% ArrayList al = (ArrayList)request.getParameter("Names"); %>
I don't know what's wrong, because is exactly as is written in the solution in the book.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
A request parameter is never a List (or ArrayList), but always a String*. If the book says that you should cast the request parameter to an ArrayList, then that book has an error in it. Are you sure you shouldn't read an attribute instead of a parameter?
* Or a String[] when you're using getParameterValues
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jack Numen
Greenhorn
Joined: Nov 09, 2011
Posts: 27
|
|
Thats a valid error since request.getParameter returns a String Object (please go through the API-documentation of HttpServletRequest).
You cannot cast a string to an ArrayList.
If you want to fetch more than one value in request object try using request.getParameterNames (returns enumeration)/ request.getParameterValues()(returns String array).
|
 |
 |
|
|
subject: Cannot cast from String to ArrayList(JSP)
|
|
|