用Java转义HTML的推荐方法有没有推荐的逃跑方法<, >, "和&在普通Java代码中输出HTML时的字符?(除手动执行以下操作外)。String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML";
String escaped = source.replace("<", "<").replace("&", "&"); // ...
3 回答
慕莱坞森
TA贡献1810条经验 获得超4个赞
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml; // ...String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML";String escaped = escapeHtml(source);
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;// ...String escaped = escapeHtml4(source);
添加回答
举报
0/150
提交
取消