Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html标记上的转义url_Html_Jsf - Fatal编程技术网

html标记上的转义url

html标记上的转义url,html,jsf,Html,Jsf,我正在这样做: 我需要这个链接指向编码的url,而不是解码的url 有人知道如何逃脱吗 更新(根据评论):我需要它来实现在facebook上共享这一功能。方法是调用以下链接:http://facebook.com/sharer.php?u=为什么需要这个?这种联系在技术上会被打破 无论如何,您基本上只需要将百分比%替换为URL编码的表示形式%25(换句话说,只需对URL编码两次) 因此,在您的特定情况下,结果将是: http%253A%252F%252Flocalhost%253A8080%2

我正在这样做:

我需要这个链接指向编码的url,而不是解码的url

有人知道如何逃脱吗


更新(根据评论):我需要它来实现在facebook上共享这一功能。方法是调用以下链接:
http://facebook.com/sharer.php?u=

为什么需要这个?这种联系在技术上会被打破

无论如何,您基本上只需要将百分比
%
替换为URL编码的表示形式
%25
(换句话说,只需对URL编码两次)

因此,在您的特定情况下,结果将是:

http%253A%252F%252Flocalhost%253A8080%252Fnews.xhtml%253Fid%253D32%2526lang%253Den 更新2:根据评论,实际需求现在已经完全清楚了,正常的JSF方式应该是(注意,这里不一定需要对其编码两次!):


有许多资源和工具可以为您实现这一点:

例如,将文本转义到


这是浏览器需要的尽可能多的转义,您的要求是什么?

我不知道您为什么要这样做,但实际上您是在双重转义真正的URL:

var s0 = "http://localhost:8080/news.xhtml?id=32&lang=en";
var s1 = escape(s0);
var s2 = escape(s1);
var s3 = unescape(s2);
var s4 = unescape(s3);
// Assume function created for echo
echo("Original: " + s0);
echo("Escape1: " + s1);
echo("Escape2: " + s2);
echo("Unescape1: " + s3);
echo("Unescape2: " + s4);
这将产生以下输出:

Original: http://localhost:8080/news.xhtml?id=32&lang=en
Escape1: http%3A//localhost%3A8080/news.xhtml%3Fid%3D32%26lang%3Den
Escape2: http%253A//localhost%253A8080/news.xhtml%253Fid%253D32%2526lang%253Den
Unescape1: http%3A//localhost%3A8080/news.xhtml%3Fid%3D32%26lang%3Den
Unescape2: http://localhost:8080/news.xhtml?id=32&lang=en

注意:通常您只想转义URL的单个参数,而不是整个URL本身。

我在后台也不清楚,但我想知道您是否有意对整个URL进行编码

我的理解是,您只需要编码任何不符合URL标准的内容,比如空格、不表示目录的前斜杠等


但是,假设您可能将URL作为get变量传递给您,也许您可以使用javascript(或jquery)之类的东西来解码链接指向的位置,而无需手动双重编码等麻烦。jquery有一个非常简单且轻松的附加组件,名为可以编码和解码。虽然源代码仍然会反映编码,但链接(无论是单击还是悬停)都会反映未编码的URL。。。我需要它来实现在facebook上共享这个功能。这样做的方法是调用以下链接:facebook.com/sharr.php?u=将来请为问题添加更多的上下文,以便整个功能需求清晰明了,而不是半途而废;)我觉得很傻。escape是否预先内置在现代ECMA/javascript中?我以为js只能在十六进制和十进制之间切换。是的,escape是全局对象上的一个函数,它与encodeURI/decodeURI和encodeURIComponent/decodeURIComponent一起在js中已经存在很长时间了。
<h:outputLink value="http://facesbook.com/sharer.php">
    <f:param name="u" value="#{bean.url}" />
</h:outputLink>
var s0 = "http://localhost:8080/news.xhtml?id=32&lang=en";
var s1 = escape(s0);
var s2 = escape(s1);
var s3 = unescape(s2);
var s4 = unescape(s3);
// Assume function created for echo
echo("Original: " + s0);
echo("Escape1: " + s1);
echo("Escape2: " + s2);
echo("Unescape1: " + s3);
echo("Unescape2: " + s4);
Original: http://localhost:8080/news.xhtml?id=32&lang=en
Escape1: http%3A//localhost%3A8080/news.xhtml%3Fid%3D32%26lang%3Den
Escape2: http%253A//localhost%253A8080/news.xhtml%253Fid%253D32%2526lang%253Den
Unescape1: http%3A//localhost%3A8080/news.xhtml%3Fid%3D32%26lang%3Den
Unescape2: http://localhost:8080/news.xhtml?id=32&lang=en