You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by yitzle <yi...@users.sourceforge.net> on 2007/06/04 22:07:40 UTC

[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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [S2] Accessing URL encoded GET data (bug found?)

Posted by an...@wipro.com.
I meant cast it to Map<String,String[]>
 
The second one is String[] (String array)
 
Try again , it wil work. 
 
Animesh
 
________________________________

From: anexpert@gmail.com on behalf of yitzle
Sent: Tue 6/5/2007 1:57 AM
To: Struts Users Mailing List
Subject: Re: [S2] Accessing URL encoded GET data (bug found?)



As per your advice, I tried explicitly casting the map to a Map<String, String>

        public void setParameters (Map map)
        {
                Map<String,String> myMap = map;
                Object m = myMap.get("criteria");
                message = m.toString();
        }

No difference. message gets set to [Ljava.lang.String;@9a8a68
Casting myMap.get("criteria") to a String gives the same error
message, ie java.lang.ClassCastException: [Ljava.lang.String; cannot
be cast to java.lang.String

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




RE: [S2] Accessing URL encoded GET data (bug found?)

Posted by an...@wipro.com.
Also it should be myMap.get("criteria")[0];
 
 
 
Animesh

________________________________

From: anexpert@gmail.com on behalf of yitzle
Sent: Tue 6/5/2007 1:57 AM
To: Struts Users Mailing List
Subject: Re: [S2] Accessing URL encoded GET data (bug found?)



As per your advice, I tried explicitly casting the map to a Map<String, String>

        public void setParameters (Map map)
        {
                Map<String,String> myMap = map;
                Object m = myMap.get("criteria");
                message = m.toString();
        }

No difference. message gets set to [Ljava.lang.String;@9a8a68
Casting myMap.get("criteria") to a String gives the same error
message, ie java.lang.ClassCastException: [Ljava.lang.String; cannot
be cast to java.lang.String

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by yitzle <yi...@users.sourceforge.net>.
As per your advice, I tried explicitly casting the map to a Map<String, String>

	public void setParameters (Map map)
	{
		Map<String,String> myMap = map;
		Object m = myMap.get("criteria");
		message = m.toString();
	}

No difference. message gets set to [Ljava.lang.String;@9a8a68
Casting myMap.get("criteria") to a String gives the same error
message, ie java.lang.ClassCastException: [Ljava.lang.String; cannot
be cast to java.lang.String

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [S2] Accessing URL encoded GET data (bug found?)

Posted by an...@wipro.com.
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: anexpert@gmail.com 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




Re: [OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by yitzle <yi...@users.sourceforge.net>.
That's why I prefer Perl ;)

On 6/4/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
> That depends on your perspective:
>
>   if("10" != 10)
>
> doesn't even compile. Some people would say that makes Java broken. :(
>
> - -chris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [double OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Animesh,

animesh.saxena@wipro.com wrote:
Christopher Schultz wrote:
>> That depends on your perspective:
>> 
>>   if("10" != 10)
>> 
>> doesn't even compile. Some people would say that makes Java broken. :(
>
> hahahaha....
> ....................
> Apply the same concept to windows operating system, and i guess the
> true answer wil be fundamentally broken OS.

Huh? I'm a linux fanboy myself, but I must be missing something.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGZIdV9CaO5/Lv0PARArGyAJ9rCusNRTky6wBTwrP7M6Guy7XCMQCgml1t
P/P0jxmr0HYJVSRrhA0sKEs=
=IXik
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by an...@wipro.com.
hahahaha....
....................
Apply the same concept to windows operating system, and i guess the true answer wil be fundamentally broken OS. 
 
Animesh
 
http://inlovewithlinux.blogspot.com
 
       	 	

________________________________

From: Christopher Schultz [mailto:chris@christopherschultz.net]
Sent: Tue 6/5/2007 3:02 AM
To: Struts Users Mailing List
Subject: Re: [OT] Re: [S2] Accessing URL encoded GET data (bug found?)



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dave,

Dave Newton wrote:
> --- yitzle <yi...@users.sourceforge.net> wrote:
>> I appreciate you taking the time to point out my
>> obvious mistakes.
>
> They're only obvious *after* you see them!
>
> I spent 10 minutes wondering why:
>
>     if ("bar" == foo)
>
> didn't work. Turns out Java's fundamentally broken.

That depends on your perspective:

  if("10" != 10)

doesn't even compile. Some people would say that makes Java broken. :(

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org <http://enigmail.mozdev.org/> 

iD8DBQFGZITv9CaO5/Lv0PARAlz9AJ9SbDcaux4henjM6z1Ws7LXkrFzuQCgvDwW
NwPkmyHd60tcU7yvnZLXGig=
=a5Ka
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




Re: [OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dave,

Dave Newton wrote:
> --- yitzle <yi...@users.sourceforge.net> wrote:
>> I appreciate you taking the time to point out my
>> obvious mistakes.
> 
> They're only obvious *after* you see them!
> 
> I spent 10 minutes wondering why:
> 
>     if ("bar" == foo)
> 
> didn't work. Turns out Java's fundamentally broken.

That depends on your perspective:

  if("10" != 10)

doesn't even compile. Some people would say that makes Java broken. :(

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGZITv9CaO5/Lv0PARAlz9AJ9SbDcaux4henjM6z1Ws7LXkrFzuQCgvDwW
NwPkmyHd60tcU7yvnZLXGig=
=a5Ka
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> I appreciate you taking the time to point out my
> obvious mistakes.

They're only obvious *after* you see them!

I spent 10 minutes wondering why:

    if ("bar" == foo)

didn't work. Turns out Java's fundamentally broken.

d.



       
____________________________________________________________________________________
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing.
http://new.toolbar.yahoo.com/toolbar/features/mail/index.php

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by yitzle <yi...@users.sourceforge.net>.
All working.
I've been doing well at making a perfect fool of myself...
I appreciate you taking the time to point out my obvious mistakes.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[OT] Re: [S2] Accessing URL encoded GET data (bug found?)

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> "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?

You quote the documentation, which tells you
*precisely* what's happening, then you write code that
does something differently, and are suprised when you
get an exception verifying what the documentation you
quoted states.

> 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[].

Why would you not use a String[] as the type of
variable you're retrieving from the map when the
documentation states that the type of the objects in
the map is String[]?

d.



       
____________________________________________________________________________________
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org