SonOfTheEARTh
SonOfTheEARTh

Reputation: 1858

passing parameters to urls in struts2?

I am working with a struts2 project and i need to pass parameters through url... this is the code that i have written

<s:url action="submit/CalculatePoints" includeParams="get" var="playerX" >
    <s:param name="winnerNo" value="player2"/>

it was refernced by following code

<a href="<s:property value="#playerX" />">

I expected that the markup for the link be

submit/CalculatePoints?winnerNo=palyer2

However iam not getting the querystring part. also attribute winnerNo in the action class is not getting populated as it should be according to How to access url parameters in struts2

Please tell me where i am going wrong?

Upvotes: 3

Views: 10571

Answers (2)

Quaternion
Quaternion

Reputation: 10458

Player2 is being evaluated not as a string but an OGNL expression simply quote Player2 and the issue will be resolved.

IE:

<s:url action="submit/CalculatePoints" includeParams="get" var="playerX" >
    <s:param name="winnerNo" value="'player2'"/>
</s:url>

Upvotes: 6

weltraumpirat
weltraumpirat

Reputation: 22604

The struts documentation for <s:url> says this:

The includeParams attribute may have the value 'none', 'get' or 'all'

Since you set this attribute to 'true', the tag seems to be ignored. Also, you must set the escapeAmp attribute to 'false'. (I assume you have a closing </s:url> somewhere else in the code).

Upvotes: 1

Related Questions