amp 显示成转义字符 in html,为什么转义字符在HTML中显示?(why are the escape characters being displayed in HTML?)...

为什么转义字符在HTML中显示?(why are the escape characters being displayed in HTML?)

我需要在显示网页上的内容之前转义一些文本,这实际上是正确完成的。 但是,当我在html中显示String时,仍将显示转义字符。 以下是这样一个例子:

hello there my ni&%ame is + - && !

以及带有转义的相应字符串如下:

hello there my ni&%ame is + - && !

我已经读过某个地方,taglib中的核心只会逃避基本的,例如>,

以下是用于将特定字符转换为其转义字符的代码的一部分:

while (character != CharacterIterator.DONE ){

if (character == '

result.append("<");

}

else if (character == '>') {

result.append(">");

}

else if (character == '&') {

result.append("&");

} .....

return result;

}

转义部分完成并完美运行..当我尝试将带有转义字符的字符串显示到html页面时出现问题

I need to escape some text before displaying the contents on the webpage, and this in fact is being done correctly. However when I display the String in html, the escape characters will still be displayed. The following is such an example:

hello there my ni&%ame is + - && !

and the respective string with escaping is the following:

hello there my ni&%ame is + - && !

I've read somewhere that the core in taglib will only escape the basic ones such as >, < , ", \t and space. however none of these escape sequences are removed from the html code. Does any of you know how to be able to solve this problem please? thanks

the following is part of the code used to convert a specific character to its escape character:

while (character != CharacterIterator.DONE ){

if (character == '

result.append("<");

}

else if (character == '>') {

result.append(">");

}

else if (character == '&') {

result.append("&");

} .....

return result;

}

the escaping part is done and works perfectly.. the problem occurs when i try to display the string with escaped characters onto an html page

原文:https://stackoverflow.com/questions/8827896

更新时间:2020-01-26 13:17

最满意答案

if (character == '

result.append("<");

}

else if (character == '>') {

result.append(">");

// ...

删除它。 你不需要它。 JSTL 已经完成了这项工作。

否则,您的HTML字符串将被转义两次。 每个&成为& 再一次等等。 如果你真的需要自己动手逃跑(为什么?)那么就根本不要使用 :

${someBean.someProperty}

或者通过escapeXml="false"关闭它的转义:

if (character == '

result.append("<");

}

else if (character == '>') {

result.append(">");

// ...

Remove this. You don't need it. The JSTL already does this job.

Your HTML string is otherwise escaped twice. Each & becomes an & again and so on. If you really need to take the escaping in own hands (why?) then just don't use at all:

${someBean.someProperty}

or turn off its escaping by escapeXml="false":

相关问答

简短的回答:

还有另一种选择:

${fn:escapeXml(myString)}

Short answer:

there is another option:

...

StringUtils.replaceEach(str, new String[]{"&", "\"", ""}, new String[]{"&", """, "<", ">"})

StringUtils.replaceEach(str, new String[]{"&", "\"", ""}, new String[]{"&", """, "<", ">"})

您可以使用html_safe。 html_safe实际上“将字符串”设置为HTML安全(它比这更复杂,但它基本上就是这样)。 这样,您可以随意从助手或模型返回HTML安全字符串。 h只能在控制器或视图中使用,因为它来自帮助程序。 它将强制输出转义。 它并没有真正被弃用,但你很可能不再使用它了:唯一的用法是“恢复”html_safe声明,非常不寻常。 使用raw前置表达式实际上等同于在其上调用html_safe,但是,就像h一样,在辅助函数上声明,因此它只能在控制器和视图上使用。 以下是关于Safe

...

尝试在标准模板中定义内容。 使其跨浏览器兼容。 String content ="

Test Me

Test Me 2.

";

Try to define the content in standard template. To make it cross browser compatible. String content ="

...

您的服务器启用了“魔术引号” 。 这会自动转义通过$_GET和$_POST进入的所有'和' 。 建议您禁用此“功能”。 PHP 5.3已弃用它,PHP 5.4已将其删除。 文件: http : //www.php.net/manual/en/security.magicquotes.php Your server has "magic quotes" enabled. This automatically escapes all ' and " that come in via $_GET and

...

为什么不让框架为你做好工作? 你可以试试HtmlEncode : string encodedHtml = Server.HtmlEncode(html);

Why not let the Framework do the work for you? You could try HtmlEncode: string encodedHtml = Server.HtmlEncode(html);

如果您使用的是Web API,则无需调用JsonConvert.SerializeObject() 。 将方法的返回类型更改为Model类(而不是string ),然后只返回模型。 Web API将为您序列化它。 If you are using Web API, then you don't need to call JsonConvert.SerializeObject(). Change the return type of your method to your Model class (

...

if (character == '

result.append("<");

}

else if (character == '>') {

result.append(">");

// ...

删除它。 你不需要它。 JSTL 已经完成了这项工作。

否则,您的HTML字符串将被转义两次。 每个&成为& 再一次等等。 如果你真的需要自己动手逃跑(为什么

...

我使用SO使用的东西。 它是opensource并具有多种语言的解析器。 名字是WMD ,问题是“WMD编辑器开源项目在哪里?” 有一些QA材料概述了这个编辑器。 “运行showdown.js服务器以将Markdown转换为HTML(在PHP中)”的问题有一些QA材料概述了PHP中的一些Markdown库。 I use what SO uses. it is opensource and has parsers for many languages. The name is WMD and the

...

不太确定真正了解整个问题。 无论如何,这是我指出的导致一些问题的因素。 当你像这样创建一个 : '' + this.typeName +''

然后this.typeName用于填充value属性和节点内容。 在后一种情况下,一切都很好,正如您所报告的那样,因为当前的typeName内容在此处没有什么特

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值