如何在struts中使用url编码参数? [英] How to encode a parameter with a url in struts?
问题描述
页面上会显示书籍列表.当用户单击一本书时,会打开其详细信息页面.现在的问题是我需要使用详细信息页面 url 对每本书的 id 进行编码.
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.
详细信息页面的链接是/loadDetailForm.do.如果图书的 id=23,则链接应显示为/loadDetailForm.do?id=23.
The link to detail page is /loadDetailForm.do. If a book has id=23, the link should appear as /loadDetailForm.do?id=23.
我在这里粘贴代码:
<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>
谢谢
推荐答案
您可以指定一个参数映射,struts 标记将这些参数附加到 url.
You can specify a map of parameters which the struts tag will append to the url.
参见 http://struts.apache.org/1.2.x/userGuide/struts-html.html#link
查看 paramId
、paramName
和 paramProperty
属性.
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>
另一种方法是使用 JSTL 标记库
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>
http://www.ibm.com/developerworks/java/图书馆/j-jstl0318/
这篇关于如何在struts中使用url编码参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!