Reputation: 5166
I have a JSP page wherein I am displaying some text in the form of a link.
<div class="col-sm-3 pull-left">
<a href="getCityDetails.action" name = "cityName"><s:property value="cityName" /></a>
</div>
Wherein I am fetching the city Name from some particular java class file through an action.
When I click the text I want it to redirect to the action getCityDetails.action, which in turn calls some method of another java class file. But along with this, I want to pass data into the action, that is the text that I have clicked. What changes should I make to accommodate this behaviour?
Upvotes: 0
Views: 3961
Reputation: 50203
Use the <s:url>
tag to build an action URL:
<s:url value="getCityDetails.action" var="url">
<s:param name="cityName" value="%{cityName}" />
</s:url>
then use it in a standard <a>
:
<a href="<s:property value="%{#url}"/>">
<s:property value="cityName" />
</a>
or in an <s:a>
:
<s:a href="%{url}">
<s:property value="cityName" />
</s:a>
Upvotes: 2
Reputation: 703
You can pass the data as a query parameter:
<div class="col-sm-3 pull-left">
<a href="getCityDetails.action?cityname=<s:property value="cityName" />" name = "cityName"><s:property value="cityName" /></a>
</div>
Upvotes: 2
Reputation: 7730
Pass Parameter within the URL
Try This
<a href="getCityDetails.action?paramToPassToAction=Value" name = "cityName"><s:property value="cityName" /></a>
Upvotes: 0