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

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

问题描述

我想为我的网站创建编码的网址。例如,对于此网址: http://google.com/index.html



我想通过URL编码将此URL提供给客户端。

解决方案

由于您使用的是JSP,我会坚持 JSTL 不使用scriptlets 。您可以使用JSTL标记 < c:url /> 结合< c:param />

 < c:url value =/ yourClientvar =url> 
< c:param name =yourParamNamevalue =http://google.com/index.html/>
< / c:url>

< a href =$ {url}>链接到您的客户< / a>

这将导致:



<$ p $ > < 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中对URL进行URL编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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