找回密码
 注册
搜索
热搜: 回贴

JSP中关于html的转换

2009-12-22 00:46| 发布者: admin| 查看: 99| 评论: 0|原作者: 夙瑶

public static String escapeHTMLTags( String input ) {
// Check if the string is null or zero length -- if so, return what was sent in.
if( input == null || input.length() == 0 ) {
return input;
}
// Use a StringBuffer in lieu of String concatenation -- it is much more efficient this way.
StringBuffer buf = new StringBuffer();
char ch = ′ ′;
for( int i=0; ich = input.charAt(i);
if( ch == ′<′ ) {
buf.append( "<" );
}
else if( ch == ′>′ ) {
buf.append( ">" );
}
else {
buf.append( ch );
}
}
return buf.toString();
}

最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 13:27 , Processed in 0.147767 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部