一个String显示在网页上,不会安置原来的格式显示,比如说,回车符在网页上就显示成了一个空格,
下面这个方法可以将String改为HTML可以辨认的格式。
public static String toHTMLString(String in) {
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'')
out.append("'");
else if (c == '\"')
out.append(""");
else if (c == '<')
out.append("<");
else if (c == '>')
out.append(">");
else if (c == '&')
out.append("&");
else if (c == ' ')
out.append(" ");
else if (c == '\n')
out.append("<br/>");
else
out.append(c);
}
return out.toString();
}
具体请查看http://blog.csdn.net/sunlen/archive/2005/02/02/278238.aspx
下面这个方法可以将String改为HTML可以辨认的格式。
public static String toHTMLString(String in) {
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'')
out.append("'");
else if (c == '\"')
out.append(""");
else if (c == '<')
out.append("<");
else if (c == '>')
out.append(">");
else if (c == '&')
out.append("&");
else if (c == ' ')
out.append(" ");
else if (c == '\n')
out.append("<br/>");
else
out.append(c);
}
return out.toString();
}
具体请查看http://blog.csdn.net/sunlen/archive/2005/02/02/278238.aspx
解决方案 »
- 地址栏中输入中文参数,后台得到乱码
- 求助struts1不能访问Action
- tomcat7.exe运行时一闪而过是怎么回事啊?求助~
- 一个java.lang.NullPointerException错误
- 向数据库中放一张图片的问题
- 请提供一个JSP+bean+sql的实例
- javax.servlet.ServletException: No getter method for property Admin_Name of bean org.apache.struts.taglib.html.BEAN
- 求包!
- 关于XML百思不得其解
- 为何用applet与servlet通讯时发生access deniess错误,是否在哪要设置一下,给分
- 编译不通过 是不是哪个jar没导入或导对???
- [求助]Resin+JDBC连接SQL Server 2000
public static String toHTMLString(String in) {
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'')
out.append("'");
else if (c == '\"')
out.append(""");
else if (c == '<')
out.append("<");
else if (c == '>')
out.append(">");
else if (c == '&')
out.append("&");
else if (c == ' ')
out.append(" ");
else if (c == '\n')
out.append("<br/>");
else
out.append(c);
}
return out.toString();
}
不知道谁知道怎么办?