1.Apache的commons-lang.jar的StringEscapeUtils.escapeHtml(str);
2. ESAPI的encodeForHTML方法。
针对用户输入的不可信数据插入页面位置进行分类
① 数据在html标签内用:encodeForHTML
② 数据在标签属性内时用:encodeForHTMLAttribute
③ 数据在JavaScript中时用:encodeForJavaScript
④ 数据在css中时用:encodeForCSS
⑤ 数据在url中时用:encodeForURL
3.jstl c:out标签也可做转义操作
4.还有一些web框架自动转义的
感觉直接用c:out最方便的
http://www.jb51.net/hack/421871.html
http://tech.finn.no/2011/04/08/xss-protection-whos-responsibility/ 看这个地方有些启发,英文的