当前位置: 动力学知识库 > 问答 > 编程问答 >

get Request parameter value in <s:text name=""/> Struts2

问题描述:

I have a url which ends:

/list.action?t=Local&st=Politics

I want to place the 2 values in 2 <s:text/>

I tried to do it this way:

<s:text name="%{#parameters['t']}"/>

<s:text name="%{#parameters['st']}"/>

But I only get the last parameter value which is "st", but not the first one.

How can I fetch multiple parameter values?

网友答案:

This is the same issue as solved here: Checking request parameter value in Struts2 tag

That being the parameter map is of type

Map<String, String[]> and not Map<String, String>

and not char[] which the single quotes of 't' evaluates to... long story short these two tags should work:

<s:text name='%{#parameters["t"]}'/>
<s:text name="%{#parameters['st']}"/>

But note that this works because of OGNL magic and it would be more explicit to write:

<s:text name='%{#parameters["t"][0]}'/>
<s:text name="%{#parameters['st'][0]}"/>

as this is working closer to the type. Anyways the above linked question should make this very clear.

分享给朋友:
您可能感兴趣的文章:
随机阅读: