You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeremy Carver <jj...@ucsd.edu> on 2007/02/26 18:29:34 UTC

[S2] Request parameter problem

Hi, I'm a new subscriber to this mailing list, so if this issue has been brought up before, I apologize.

I am having trouble retrieving request parameters in my action class, using the recommended method described in http://struts.apache.org/2.x/docs/how-can-we-access-request-parameters-passed-into-an-action.html.  The objects contained in the parameter Map appear to be corrupted in some way, and cannot be cast to any meaningful class (such as String).

To be more precise, my JSP contains the following code:

    ...
    <s:iterator value="%{#session.folders}" id="folder">
      <s:url id="folderUrl" action="folder" method="display">
        <s:param name="id" value="%{#folder.id}"/>
      </s:url>
      ...
      <s:a href="%{folderUrl}">
        <s:property value="name"/>
      </s:a>
      ...
    </s:iterator>

There is a collection of "Folder" objects stored as a session attribute under key "folders".  Each Folder object has a propert called "id" of type Long.  This code correctly iterates over this collection and prints out the properly formulated hyperlink with "id" request parameter, without any problems.

My action class properly implements the ParameterAware interface, and the servlet-config interceptor is properly registered to the action, as per the instructions linked above.  However, when I attempt to access the request parameter using the following action code, I get a ClassCastException:

    String folderId = (String)getParameters().get("id");

I understand that according to documentation found at http://struts.apache.org/2.x/docs/param.html, the "param" tag's value might evaluate to an Object rather than a String if I use the above tag syntax, so I tried changing my JSP code to

    <s:url id="folderUrl" action="folder" method="display">
      <s:param name="id">
        <s:property value="id"/>
      </s:param>
    </s:url>

to force evaluation as a String, but the same problem occurs.  After some investigation, I found that no matter how I code the request parameter, if I test the resulting Map value for its class type with code such as

    System.err.println(getParameters().get("id").getClass().getName());

I receive the following value:

    [Ljava.lang.String;

Apparently it's like some altered form of String, that cannot be cast to a true String without causing a ClassCastException, and cannot have its String value printed out with toString() because doing so yields some gibberish like

    [Ljava.lang.String;@898587

rather than the desired value.  However, I am quite sure that the object being retrieved does represent the request parameter I attempted to send, because using the Eclipse debugger I see a single value in the parameter Map under key "id", which contains the value I wanted it to.  I just can't get at that value because the object's type is corrupted in the manner explained above.  So, I do not know how to properly retrieve the parameter's value in the action class.

I apologize for the length of this email, I just wanted to be sure to include all potentially relevant information.  If anyone is familiar with this issue or could point me toward some documentation that addresses it, I would greatly appreciate it.  Thank you very much for your time.

Jeremy Carver

Re: [S2] Request parameter problem

Posted by Jeremy Carver <jj...@ucsd.edu>.
Oh...thanks, hehe.  How simple.

Jeremy Carver


----- Original Message ----- 
From: "Dave Newton" <ne...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Monday, February 26, 2007 9:36 AM
Subject: Re: [S2] Request parameter problem


> --- Jeremy Carver <jj...@ucsd.edu> wrote:
>>     [Ljava.lang.String;
>>
>> Apparently it's like some altered form of String,
>
> That's a String array.
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> It's here! Your new message!
> Get new email alerts with the free Yahoo! Toolbar.
> http://tools.search.yahoo.com/toolbar/features/mail/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 



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


Re: [S2] Request parameter problem

Posted by Dave Newton <ne...@yahoo.com>.
--- Jeremy Carver <jj...@ucsd.edu> wrote:
>     [Ljava.lang.String;
> 
> Apparently it's like some altered form of String,

That's a String array.

d.



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

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