直接保存,然后当从数据库中取出来时用过滤方法过滤一遍再送回页面即可,给一段代码,看了就明白了,你可以自己扩充
public static String filter(String value) { if (value == null)
return (null); StringBuffer result = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (ch == '<')
result.append("<");
else if (ch == '>')
result.append(">");
else if (ch == '&')
result.append("&");
else if (ch == '"')
result.append(""");
else if (ch == '\r')
result.append("<BR>");
else if (ch == '\n') {
if (i > 0 && value.charAt(i - 1) == '\r') { } else {
result.append("<BR>");
}
} else if (ch == '\t')
result.append("  ");
else if (ch == ' ')
result.append(" ");
else
result.append(ch);
}
return (result.toString());
}
public static String filter(String value) { if (value == null)
return (null); StringBuffer result = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (ch == '<')
result.append("<");
else if (ch == '>')
result.append(">");
else if (ch == '&')
result.append("&");
else if (ch == '"')
result.append(""");
else if (ch == '\r')
result.append("<BR>");
else if (ch == '\n') {
if (i > 0 && value.charAt(i - 1) == '\r') { } else {
result.append("<BR>");
}
} else if (ch == '\t')
result.append("  ");
else if (ch == ' ')
result.append(" ");
else
result.append(ch);
}
return (result.toString());
}
解决方案 »
- struts1 的类型转换器 代码求解释
- 一道计算题深刻理解Jvm,求解原理(菜鸟题目也不会)
- SOAP消息中的xmlns问题
- LinkedHashMap和HashMap的区别
- logic iterate的问题
- 刚来报道,请教赋值问题。。。
- 实例分析struts的Action类?
- j2ee启动后包括了tomcat?
- 请教关于Web Services的开发
- 哪位可以解释一下jms,及其与ejb2.0的相关内容。推荐一些资料和具体网址更好,谢谢。
- 请教:如何将一个工程产生的jar文件,导入另一个需要该jar文件的工程中?(急)
- 我在webapps/root/目录下建了一个index.html,当我再启动tomcat时,欢迎主页就是index.html而不是默认的index.jsp了,为什么?
把空格回车替换出来就可以了
a
b
c
d
就变成a<br>b<br>c<br>d了
怎么办?
如果你是用Struts的bean:write来显示的话,别忘了加上,filter="false"
<bean:write name="info" property="content" filter="false"/>
结果显示出来就变成了a<br>b了