无法使用 VelocityEngine 使徽标显示在 html 页面(<img> 标签)上

问题描述 投票:0回答:1
java image velocity
1个回答
0
投票

esc.url
函数内部使用
URLEncoder.encode
,它通常用于对URL的查询字符串部分进行编码。您的 URL
https://s3.amazonaws.com/static.myproject.com/project-static/logos/my-logo.png
没有查询字符串,因此不需要编码。
$esc.url('https://s3.amazonaws.com/static.myproject.com/project-static/logos/my-logo.png')
会返回类似于
https%3A%2F%2Fs3.amazonaws.com%2Fstatic.myproject.com%2Fproject-static%2Flogos%2Fmy-logo.png
的内容,这不是有效的 URL,因此会出现您看到的错误。您应该完全删除转义、仅转义查询字符串部分或仅转义查询字符串中 URL 中不允许出现字符的特定部分。像下面这样:

<img src="https://s3.amazonaws.com/static.myproject.com/project-static/logos/my-logo.png?label=$esc.url('small size')" alt="PR logo">
© www.soinside.com 2019 - 2024. All rights reserved.