--- Begin Message ---
You are tryin to cast a string array to string. parameters are passed as 
key/value pairs of Strings to the web server, so the we assume that the 
generics mapping for parameters is <String, String>. In fact, compilers will 
allow you to use this generic: 
Map<String,String> parameters = request.getParameterMap();
for(String key: parameters.keySet()) {
String value = parameters.get(key); // error happens here
System.out.println(key + "=" + value);
}

 

Use somethin like Map<String,String[]> parameters = request.getParameterMap();
When you call request.getParameter("firstName");, it simply returns the 
equivalent of parameters.get(key)[0];

Hope this helps

 

Animesh

 
 
________________________________

From: [EMAIL PROTECTED] on behalf of yitzle
Sent: Tue 6/5/2007 1:37 AM
To: Struts Users Mailing List
Subject: [S2] Accessing URL encoded GET data (bug found?)



I am implementing the ParamterAware interface to get to the parameter.
The interface has a setParameters(Map parameters) that I'm supposed to
be able to use to access the GET data encoded in the URL.
>From the JavaDoc API:
"Note that all parameter values for a given name will be returned, so
the type of the objects in the map is java.lang.String[]."

When I try reading data from the Map and converting to a String, I get
a casting error:
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to
java.lang.String


I did this:
        public void setParameters (Map map)
        {
                Object m = map.get("criteria");
                message = m.toString();
        }
then displayed the message. I get "[Ljava.lang.String;@e35bb7"

Any clues? Bug?

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



<<winmail.dat>>


--- End Message ---
The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.
 
www.wipro.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to