日期:2014-05-18 浏览次数:20680 次
//特殊字符转为Html
public static String toHtml(String s) {
s = Replace(s,"&","&");
s = Replace(s,"<","<");
s = Replace(s,">",">");
s = Replace(s,"\t"," ");
s = Replace(s,"\r\n","\n");
s = Replace(s,"\n","<br>");
s = Replace(s," "," ");
s = Replace(s,"'","'");
s = Replace(s,"\\","\");
return s;
}
//逆
public static String unHtml(String s){
s = Replace(s,"<br>","\n");
s = Replace(s," "," ");
s = Replace(s,"<","<");
s = Replace(s,">",">");
s = Replace(s,"&","&");
return s;
}
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<input type="text" value="${fn:escapeXml(user.name)}" />