How to encode a parameter with a url in struts?
문제
A list of books is displayed on the page. When a user clicks a book, its detail page is opened. Now the problem is that I need to encode each book's id with the detail page url.
The link to detail page is /loadDetailForm.do. If a book has id=23, the link should appear as /loadDetailForm.do?id=23.
I am pasting code here:
<logic:notEmpty name="BrowseForm" property="books">
<logic:iterate id="book" property="books" name="BrowseForm" type="com.nms.bks.app1.domain.Book">
<p><html:link action="/loadDetailForm" styleClass="btn_blue"><bean:write name="book" property="title"/></html:link></p>
</logic:iterate>
</logic:notEmpty>
Thanks
해결책
You can specify a map of parameters which the struts tag will append to the url.
See http://struts.apache.org/1.2.x/userGuide/struts-html.html#link
Look at the paramId
, paramName
and paramProperty
attributes.
<html:link action="/loadDetailForm"
styleClass="btn_blue"
paramId="id"
paramName="book"
paramProperty="id">
<bean:write name="book" property="title"/>
</html:link>
An alternative would be to use the JSTL tag library
<c:url value="expression" context="expression"
var="name" scope="scope">
<c:param name="param1" value="${thing.id}"/>
...
</c:url>
제휴하지 않습니다 StackOverflow