如何在JSP/JSTL中对URL进行URL编码? [英] How to URL encode a URL in JSP / JSTL?

查看:431
本文介绍了如何在JSP/JSTL中对URL进行URL编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的网站创建一个编码的 URL .例如,对于该URL:" http://google.com/index.html "

我想通过URL编码将该URL提供给客户端.

解决方案

由于您使用的是JSP,因此我会坚持使用 JSTL 不使用脚本集.您可以将JSTL标记 <c:url /><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>

这将导致:

<a href="/yourClient?yourParamName=http%3a%2f%2fgoogle.com%2findex.html">Link to your client</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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆