日期:2014-05-19  浏览次数:20736 次

EL表达要取的值中包含双引号"" 单引号'' 怎么办?撒分!
EL表达要取的值中有双引号""也有单引号'' 怎么办?
如 <input type="text" value="${user.name}" 这种情况如果name本包含双引号和单引号咋办,用[]来取貌似都不行啊

------解决方案--------------------
楼主,在后台数据查询出来的时候,要返回页面上的值有单双引号的,你可以写个方法转义一下,应该就行了。像这种一样:
Java code

//特殊字符转为Html
public static String toHtml(String s) {
    s = Replace(s,"&","&amp;");
    s = Replace(s,"<","&lt;");
    s = Replace(s,">","&gt;");
    s = Replace(s,"\t","    ");
    s = Replace(s,"\r\n","\n");
    s = Replace(s,"\n","<br>");
    s = Replace(s,"  "," &nbsp;");
    s = Replace(s,"'","&#39;");
    s = Replace(s,"\\","&#92;");
    return s;
}
//逆
public static String unHtml(String s){    
    s = Replace(s,"<br>","\n");
    s = Replace(s,"&nbsp;"," ");
    s = Replace(s,"&lt","<");
    s = Replace(s,"&gt",">");
    s = Replace(s,"&amp","&");
    return s;
}

------解决方案--------------------
引进JSTL Funciton
HTML code

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>