user860564
user860564

Reputation: 11

How to pass parameters from a s:a to the action in struts2

I'm using Struts2. I need to pass a parameter from my jsp to the action. The parameter is different depending on which link we want to see although the action is the same. I don't know how to do this... My code without passing parameters is this:

<% if (usuario.getComputeEngines().size() > 0) { 
                int contador = 1;
                Long idCE;
                for (int i=0; i < usuario.getComputeEngines().size(); i++){
                    idCE = usuario.getComputeEngines().get(i).getIdComputeEngine();
                    %>
                <td width="50%" align="center" valign="top">
                    <br clear=all>
                    <s:a href="%{CE}"><img src="images/casa<%out.println(contador); %>
                    .jpg" border="0"></s:a>
                    <br><%=i%>
                    <br>
                </td>

The parameter i need to pass to the action is i. It's just a number. How could I do this? Thanks in advanced!

Upvotes: 1

Views: 10383

Answers (2)

Zemzela
Zemzela

Reputation: 3080

you can pass a parameter in

    <s:url ="CE" action="action">
            <s:param name="name" value="value"/>
    </s:url>

Upvotes: 0

Russell Shingleton
Russell Shingleton

Reputation: 3196

<s:url ="CE" action="action">
        <s:param name="name" value="value"/>
</s:url>

This is only part of it, and it needs an id. You need to then associate the url with the anchor tag:

<s:url id="myUrl" action="action">
        <s:param name="name" value="value"/>
</s:url>

<s:a href="%{myUrl}"><img src="images/casa<%out.println(contador); %>
                .jpg" border="0"></s:a>

You can put as many tags in there as you want. I've also noticed that the form...

<s:param name="name" value="value"/>

...sometimes does not work and I tend to use:

<s:param name="name">value</s:param>

Upvotes: 3

Related Questions