Search code examples
javajspstruts2hyperlinkhref

Struts 2 action linked to a clickable link


I'm trying to add an action to a link inside a list item

It's inside a form:

<form name="searchForm" method="post" action="searchThis" id="querySubmiter">

Inside a list:

<li><a href="somePage.jsp"><img src="img/Logo/myLogo.png"/></a>

I'm a bit clueless as to how to make the connection. Is it possible?


Solution

  • Use Struts 2 tags like

    <s:a action="searchThis"><img src="<s:url value="/img/Logo/myLogo.png"/>"/></s:a>
    

    There would be generated an anchor tag with the image. Note to use <s:url> tag to correctly define the path to the static resource. Also combined with <s:param> tag you could construct any link. See the documentation with example of the <s:a> tag.