论坛回复数据显示问题? 用户在textarea中输入的回复信息如果直接显示在页面上,不能显示其中的回车我看很多人都是转换一下回复信息,但是不到需要转换成什么样。希望大家指点一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 文本里的换行,在html里是不会被解析成换行的,你必须把文本里的换行替换成<br>标签 我也这么想过,可是对于字符串"ajkfakdf<br>sdfg"中的"<br>"通过页面显示并不会回车呀,显示的还是<br>呀?难道把文本中的换行转换成<br>就能够回车了吗?请赐教!!! 使用文本编辑器 比如说eWebEditor 下面这个就是我一直用的,html字符过滤工具,应该就是你要的public class CodeFilter{ public CodeFilter(){ } public static String toHtml(String s){ if(s == null){ s = ""; return s; } s = Replace(s.trim(),"&","&"); s = Replace(s.trim(),"<","<"); s = Replace(s.trim(),">",">"); s = Replace(s.trim(),"\t"," "); s = Replace(s.trim(),"\r\n","\n"); s = Replace(s.trim(),"\n","<br>"); s = Replace(s.trim()," "," "); //s = Replace(s.trim(),"'","'"); s = Replace(s.trim(),"\\","\"); return s; } public static String unHtml(String s){ s = Replace(s,"<br>","\n"); s = Replace(s," "," "); return s; }//Replace public static String Replace(String source,String oldString,String newString){ StringBuffer output = new StringBuffer(); int lengthOfsource = source.length(); int lengthOfold = oldString.length(); int posStart = 0; int pos; while((pos = source.indexOf(oldString,posStart)) >= 0){ output.append(source.substring(posStart,pos)); output.append(newString); posStart = pos + lengthOfold; } if(posStart < lengthOfsource){ output.append(source.substring(posStart)); } return output.toString(); }} 谢谢了(zhangj0571(笨鸟飞飞)) 求一个JS执行时以本地IP提交 Unknown tag问题请教高手 checkbox 全选的时 如何不把控制 全选 的那个复选框 在 提交表单的时候不传直到后台? 一个代理服务器程序的问题 Hibernate 创建SessionFactory失败,怎么回事? javascript 如何实现不让表单bea提交 页面标签的问题,很头疼,帮忙看看...... jsp网页如何在加载时自动执行serverlet查询数据库? 高手请进,将程序加为服务 100分求助log4j问题 【小女子不易啊】现在流行的什么 VO BI BS 都是什么东西啊 天天听旁边的男程序员说起 我还不好意思问
"ajkfakdf<br>sdfg"中的"<br>"通过页面显示并不会回车呀,显示的还是<br>呀?
难道把文本中的换行转换成<br>就能够回车了吗?
请赐教!!!
public CodeFilter(){
}
public static String toHtml(String s){
if(s == null){
s = "";
return s;
}
s = Replace(s.trim(),"&","&");
s = Replace(s.trim(),"<","<");
s = Replace(s.trim(),">",">");
s = Replace(s.trim(),"\t"," ");
s = Replace(s.trim(),"\r\n","\n");
s = Replace(s.trim(),"\n","<br>");
s = Replace(s.trim()," "," ");
//s = Replace(s.trim(),"'","'");
s = Replace(s.trim(),"\\","\");
return s;
}
public static String unHtml(String s){
s = Replace(s,"<br>","\n");
s = Replace(s," "," ");
return s;
}//Replace
public static String Replace(String source,String oldString,String newString){ StringBuffer output = new StringBuffer(); int lengthOfsource = source.length();
int lengthOfold = oldString.length(); int posStart = 0;
int pos; while((pos = source.indexOf(oldString,posStart)) >= 0){
output.append(source.substring(posStart,pos));
output.append(newString); posStart = pos + lengthOfold; } if(posStart < lengthOfsource){
output.append(source.substring(posStart));
}
return output.toString();
}
}