i have a variable called param
, which has the value I told \"I will e\"
, in JSP am assigning this to a input tag's value as
<input type="text" value="${param}"/>
what is happening is that the value am getting is I told \
, i.e am getting value only till the first ", but am escaping this " with a \,but still am getting this. how can I solve this?
i have a variable called param
, which has the value I told \"I will e\"
, in JSP am assigning this to a input tag's value as
<input type="text" value="${param}"/>
what is happening is that the value am getting is I told \
, i.e am getting value only till the first ", but am escaping this " with a \,but still am getting this. how can I solve this?
-
You're escaping it in the JSTL, but the generated HTML will still be
value="I told "I will e""
. You need to escape it in the HTML using the\"
, so your JSTL variable will likely need to be: I told \\"I will e\\". – Anthony Grist Commented Jan 7, 2013 at 15:45 - @AnthonyGrist How can I achieve that? should i do while I assign the value to variable by saying something like " – Seeker Commented Jan 7, 2013 at 15:48
-
1
This is something that
fn:escapeXml()
should do, but I'm not sure it does. – Pointy Commented Jan 7, 2013 at 15:49 - 2 possible duplicate of JSTL function to replace quote chars inside a string? – BalusC Commented Jan 7, 2013 at 16:53
2 Answers
Reset to default 6Try this:
<input type="text" value="${fn:escapeXml(param)}"/>
That will work when the escaping you need is in fact XML/HTML escaping. If you're dropping the JSTL/EL expression into JavaScript code, however, that's probably not what you want. In that case you'd want a JSON encoding function, of which there are several available I think (from Google at least). (I've got my own so I can't provide direct information.)
If you want to stick with the Core library of JSTL, this also does the trick:
<c:out value="${param}" />