Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Struts2 converting my string to a string array?
    primarykey
    data
    text
    <p>I have a Struts 2 (JDK 1.7, Struts 2.2.1) application that contains a list of filtering criteria, stored as strings in a map.</p> <pre><code>Map&lt; String, String &gt; m_filters = new HashMap&lt; String, String &gt;(); public Map&lt; String, String &gt; getFilters() { return m_filters; } </code></pre> <p>I pass a URL formatted like this:</p> <p><a href="http://myserver.com/myapp/GenerateReport.action?reportID=Whatever&amp;filters.fromDate=0&amp;filters.toDate=2000000000&amp;filters.FcsType=piv_cardholder_3kp&amp;detailed=true">http://myserver.com/myapp/GenerateReport.action?reportID=Whatever&amp;filters.fromDate=0&amp;filters.toDate=2000000000&amp;filters.FcsType=piv_cardholder_3kp&amp;detailed=true</a></p> <p>Even though the Map has both key &amp; value types specified as String, attempting to get a value from this </p> <pre><code> Map&lt; String, String &gt; filters = getFilters(); String value = filters.get( "fromDate" ); </code></pre> <p>causes this exception to be thrown:</p> <p><code>java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String</code></p> <p>I reproduced this in a unit test, and confirmed in a debugger that Struts 2 seems to be creating a String[1] instead of a String for each of the parameters. i.e. it is a length-1 string array with the only string being the expected value ("0" in this case).</p> <p><strong>My question is:</strong> Is this a bug in Struts2, or am I doing something incorrectly?</p> <p>If it is a bug, is there a known workaround?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload