Reputation: 586
I need to escape " and \ in jsp, but not necessarily in the same time.
With <c:out var="${value}" />
I can escape "
character.
With ${fn:replace(value,'\\','\')}
I can escape the \
character, and is working fine.
I tried to handle both cases as follows.
I tried to use
<c:out var="${fn:replace(value,'\\','\')}"/>
but is not working, is not accepted, seems to be an error.
I also tried to put in a variable
the string after replace, and after that using it in c:out
, but was the same thing.
If anyone has an idea of a way to handle both cases, please let me know.
Note: the input comes from Java
, that's why I used \\
, and is sent forward as JSON
.
Thanks
Upvotes: 2
Views: 3972
Reputation: 586
I found the best solution to be StringEscapeUtils from Apache
, and I had to create a taglib as @Tap said, and added jar file commons-lang to project . This has a lot of functions for working with strings.
More details can be found here ->
Upvotes: 1
Reputation: 6522
You could call fn:replace()
twice, chaining the calls, to replace both characters.
${fn:replace(fn:replace(value,'\\','\'),'\"','"')}
It's not very pretty, though.
Upvotes: 3