You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mufaddal Khumri <mu...@wmotion.com> on 2003/04/22 10:57:08 UTC

Que on passing String [] using request.setAttribute ....

Hi,

I am trying to set an attribute "d" in my servlet to a String array:

String dArray[] = new String[10];
request.setAttribute("d",  dArray);

In my jsp :
<%
String [] dw = (String [])request.getAttribute("d");
%>
The above code causes a class cast exception !.

<%
Object dw = (Object)request.getAttribute("d");
if(dw != null)
		out.println("<p>dw.toString() = " + d.toString() + "</p>");
%>		
I can cast it to type Object, but toString() returns blank. I thought I 
can treat an array as an Object. What am i doing wrong ? I need to get 
the String array back.

Thanks.


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


Re: Que on passing String [] using request.setAttribute ....

Posted by Mufaddal Khumri <mu...@wmotion.com>.
String [] dArray OR String dArray[]  is the same. When i try to do 
dw.getClass() .. it says java.lang.String .

Why dont I get a String array back when i do the following ?
<%
String [] dw= (String [])request.getAttribute("d");
%>
The above code throws a class cast exception.

On Wednesday, April 23, 2003, at 03:11  AM, Andre John Mas wrote:

> Mufaddal Khumri wrote:
>> Hi,
>> I am trying to set an attribute "d" in my servlet to a String array:
>> String dArray[] = new String[10];
>> request.setAttribute("d",  dArray);
>
> Are your sure this should not be:
>
>  String[] dArray = new String[10];
>  request.setAttribute("d",  dArray);
>
>> In my jsp :
>> <%
>> String [] dw = (String [])request.getAttribute("d");
>> %>
>> The above code causes a class cast exception !.
>
> If the object being set is indeed an array then the above should work.
> One way of checking the class is:
>
> <%
> Object dw = request.getAttribute("d");
> %>
> <%=dw.getClass()%>
>
>> <%
>> Object dw = (Object)request.getAttribute("d");
>> if(dw != null)
>>         out.println("<p>dw.toString() = " + d.toString() + "</p>");
>> %>
>
> The return value of toString() will depend on the implementation by the
> class or one of it ancestors.
>
>> I can cast it to type Object, but toString() returns blank. I thought 
>> I can treat an array as an Object. What am i doing wrong ? I need to 
>> get the String array back.
>> Thanks.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> -- 
> André-John Mas
> Software Developer / Développeur Informatique
> Newtrade Technologies Inc.
> 63 de Brésoles, Suite 100
> Montreal, Quebec, Canada H2Y 1V7
> mailto:ajmas@newtrade.com
> tel +1 514 286 8180 x3017
> fax +1 514 286 8184
>
> ----------------------------------------------------------------------
> If you have received this message in error, please notify the sender
> immediately and delete the original without making a copy, disclosing
> its contents or taking any action based thereon.
>
> Si vous avez reçu ce message par erreur, veuillez en aviser
> immédiatement le signataire et effacer l'original, sans en tirer de
> copie, en dévoiler le contenu ni prendre quelque mesure fondée sur
> celui-ci.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


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


Re: Que on passing String [] using request.setAttribute ....

Posted by Andre John Mas <aj...@newtradetech.com>.
Mufaddal Khumri wrote:
> Hi,
> 
> I am trying to set an attribute "d" in my servlet to a String array:
> 
> String dArray[] = new String[10];
> request.setAttribute("d",  dArray);

Are your sure this should not be:

  String[] dArray = new String[10];
  request.setAttribute("d",  dArray);

> In my jsp :
> <%
> String [] dw = (String [])request.getAttribute("d");
> %>
> The above code causes a class cast exception !.

If the object being set is indeed an array then the above should work.
One way of checking the class is:

<%
Object dw = request.getAttribute("d");
%>
<%=dw.getClass()%>

> <%
> Object dw = (Object)request.getAttribute("d");
> if(dw != null)
>         out.println("<p>dw.toString() = " + d.toString() + "</p>");
> %>       

The return value of toString() will depend on the implementation by the
class or one of it ancestors.

> I can cast it to type Object, but toString() returns blank. I thought I 
> can treat an array as an Object. What am i doing wrong ? I need to get 
> the String array back.
> 
> Thanks.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


-- 
André-John Mas
Software Developer / Développeur Informatique
Newtrade Technologies Inc.
63 de Brésoles, Suite 100
Montreal, Quebec, Canada H2Y 1V7
mailto:ajmas@newtrade.com
tel +1 514 286 8180 x3017
fax +1 514 286 8184

----------------------------------------------------------------------
If you have received this message in error, please notify the sender
immediately and delete the original without making a copy, disclosing
its contents or taking any action based thereon.

Si vous avez reçu ce message par erreur, veuillez en aviser
immédiatement le signataire et effacer l'original, sans en tirer de
copie, en dévoiler le contenu ni prendre quelque mesure fondée sur
celui-ci.



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