在保存到数据库的时候,我把录入的空格,顿号,引号等都过滤成了html代码,比如 &nbsp。
在读取到页面的时候,需要把html再次转化成空格。
c:out标签,有 escapeXml="false"属性,那html:text标签有没有相应的属性?

解决方案 »

  1.   

    给你个封装好的,我们项目就用这个private static String htmlEncode(String text) {
            if(text==null || "".equals(text))
                return "";
            text = text.replace("<", "&lt;");
            text = text.replace(">", "&gt;");
            text = text.replace(" ", "&nbsp;");
            text = text.replace("\"", "&quot;");
            text = text.replace("\'", "&apos;");
            return text.replace("\n", "<br/>");
        }
        
        public static String textEncode(String text) {
            if(text==null || "".equals(text))
                return "";
            text = text.replace("&lt;", "<");
            text = text.replace("&gt;", ">");
            text = text.replace("&nbsp;", " ");
            text = text.replace("&quot;", "\"");
            text = text.replace("&apos;", "\'");
            return text.replace("<br/>", "\n");
        }上面那个是从数据库取后到页面时用到的,下面的正好相反!你试试看