简体   繁体   English

在NVelocity中转义

[英]escaping a " in NVelocity

how can I escape " in NVelocity ? 我如何在NVelocity中逃脱?

eg test.message = "136# 1/4" Test Test Test" 例如test.message =“ 136#1/4” Test Test Test“

if I do <input type="text" id="Test.Description" value="$test.message"/> 如果我做<input type="text" id="Test.Description" value="$test.message"/>

it displays : 136# 1/4 它显示:136#1/4

if I do <input type="text" id="Test.Description" value=$test.message/> 如果我<input type="text" id="Test.Description" value=$test.message/>

it displays : 136 它显示:136

if I do <input type="text" id="Test.Description" value='$test.message'/> 如果我<input type="text" id="Test.Description" value='$test.message'/>

it displays : 136# 1/4" Test Test Test but it escapes ' 它显示:136#1/4“ Test Test Test但它逃脱了'

how can I display 136# 1/4" Test Test Test without escaping anything ? 如何显示136#1/4“测试测试测试而没有转义?

nVelocity, at this time, has no built-in facility for HTML-encoding it's variables (there has been some talk about adding it in a future version) 目前,nVelocity还没有用于对其变量进行HTML编码的内置功能(有人谈论在将来的版本中添加它)

In the meantime, in your controller, you'll just need to do: 同时,在您的控制器中,您只需要执行以下操作:

test.message = HttpUtility.HtmlEncode(test.message);

or 要么

test.message = test.message.Replace("\"", "&quot;");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM