escaping a " in NVelocity
-
14-09-2020 - |
题
how can I escape " in NVelocity ?
e.g. test.message = "136# 1/4" Test Test Test"
if I do <input type="text" id="Test.Description" value="$test.message"/>
it displays : 136# 1/4
if I do <input type="text" id="Test.Description" value=$test.message/>
it displays : 136
if I do <input type="text" id="Test.Description" value='$test.message'/>
it displays : 136# 1/4" Test Test Test but it escapes '
how can I display 136# 1/4" Test Test Test without escaping anything ?
解决方案
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)
In the meantime, in your controller, you'll just need to do:
test.message = HttpUtility.HtmlEncode(test.message);
or
test.message = test.message.Replace("\"", """);
不隶属于 StackOverflow