如何在 JSP/JSTL 中对 URL 进行 URL 编码? [英] How to URL encode a URL in JSP / JSTL?
本文介绍了如何在 JSP/JSTL 中对 URL 进行 URL 编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的网站创建一个编码的URL.例如,对于这个 URL:http://google.com/index.html">
我想通过 URL 编码将这个 URL 提供给客户端.
解决方案
既然你使用的是 JSP,我会坚持使用 JSTL 和 不使用 scriptlets.您可以使用 JSTL 标记 <c:url/>
结合
:
<c:param name="yourParamName" value="http://google.com/index.html"/></c:url><a href="${url}">链接到您的客户</a>
这将导致:
<a href="/yourClient?yourParamName=http%3a%2f%2fgoogle.com%2findex.html">链接到您的客户</a>
I want to create an encoded URL for my site. Say for example, for this URL: "http://google.com/index.html"
I want to give this URL to the client by URL encoding it.
解决方案
Since you are using JSP, I would stick to JSTL and not use scriptlets. You could use the JSTL tag <c:url />
in combination with <c:param />
:
<c:url value="/yourClient" var="url">
<c:param name="yourParamName" value="http://google.com/index.html" />
</c:url>
<a href="${url}">Link to your client</a>
This will result in:
<a href="/yourClient?yourParamName=http%3a%2f%2fgoogle.com%2findex.html">Link to your client</a>
这篇关于如何在 JSP/JSTL 中对 URL 进行 URL 编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文