Seeker
Seeker

Reputation: 2475

escaping quote in JSTL

i have a variable called param, which has the value I told \"I will come\", 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?

Upvotes: 1

Views: 9317

Answers (2)

Med
Med

Reputation: 628

If you want to stick with the Core library of JSTL, this also does the trick:

<c:out value="${param}" />

Upvotes: 1

Pointy
Pointy

Reputation: 414016

Try 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.)

Upvotes: 6

Related Questions