html:text 如何过滤html代码?

乾K大挪移 2009-07-14 08:51:51
在保存到数据库的时候,我把录入的空格,顿号,引号等都过滤成了html代码,比如  。
在读取到页面的时候,需要把html再次转化成空格。
c:out标签,有 escapeXml="false"属性,那html:text标签有没有相应的属性?
...全文
57 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxalxpks 2009-07-15
  • 打赏
  • 举报
回复
顶个
DefunctMan 2009-07-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 baishengjie 的回复:]
给你个封装好的,我们项目就用这个

Java code
private static String htmlEncode(String text) {
if(text==null || "".equals(text))
return "";
text = text.replace("<", "<");
text = text.replace(">", ">");
text = text.replace(" ", " ");
text = text.replace("\"", """);
text = text.replace("\'", "'");
ret…
[/Quote]

后台处理。
lee90649 2009-07-14
  • 打赏
  • 举报
回复
学习来了!~
baishengjie 2009-07-14
  • 打赏
  • 举报
回复
给你个封装好的,我们项目就用这个

private static String htmlEncode(String text) {
if(text==null || "".equals(text))
return "";
text = text.replace("<", "<");
text = text.replace(">", ">");
text = text.replace(" ", " ");
text = text.replace("\"", """);
text = text.replace("\'", "'");
return text.replace("\n", "<br/>");
}

public static String textEncode(String text) {
if(text==null || "".equals(text))
return "";
text = text.replace("<", "<");
text = text.replace(">", ">");
text = text.replace(" ", " ");
text = text.replace(""", "\"");
text = text.replace("'", "\'");
return text.replace("<br/>", "\n");
}

上面那个是从数据库取后到页面时用到的,下面的正好相反!你试试看
DefunctMan 2009-07-14
  • 打赏
  • 举报
回复
看了文档上面说没有。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧