Sending & in query String

一曲冷凌霜 提交于 2019-12-31 05:36:13

问题


From first.jsp I am sending some parameters to result.jsp as -

<a href="result.jsp?itemId=${itemId}&itemName=${item.itemName}&itemCode=${item.itemCode}')">Show Items</a>

Here ${item.itemName} can have values like "food & stationary". When item name contains an "&", I am not able to get whole value on result page, its printing only "food". Is there any way (in JSTL or any) so that I can encode "&". I know if I would convert "&" to "%26" then this would correct.


回答1:


Use JSTL's c:url and c:param for that. Basic example:

<a href="<c:url value="result.jsp">
    <c:param name="itemId" value="${itemId}" />
    <c:param name="itemName" value="${item.itemName}" />
    <c:param name="itemCode" value="${item.itemCode}" />
</c:url>">Show Items</a>


来源:https://stackoverflow.com/questions/1761281/sending-in-query-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!