使用Apache
StringEscapeUtils.escapeJavascript函数。
Escapes the characters in a String using Javascript String rules.Escapes any values it finds into their Javascript String form.Deals correctly with quotes and control-chars (tab, backslash, cr, ff,etc.)
So a tab becomes the characters '\' and 't'.



