return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - escaping quote in JSTL - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - escaping quote in JSTL - Stack Overflow

programmeradmin0浏览0评论

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?

Share Improve this question asked Jan 7, 2013 at 15:43 SeekerSeeker 2,4756 gold badges50 silver badges84 bronze badges 4
  • 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 &quot – 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
Add a ment  | 

2 Answers 2

Reset to default 6

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

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

<c:out value="${param}" />
发布评论

评论列表(0)

  1. 暂无评论