JSP中关于HTML的转换
类别: JSP教程
请看下面这个例子
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; i<input.length(); i++ ) {
ch = input.charAt(i);
if( ch == ´<´ ) {
buf.append( "<" );
}
else if( ch == ´>´ ) {
buf.append( ">" );
}
else {
buf.append( ch );
}
}
return buf.toString();
}
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; i<input.length(); i++ ) {
ch = input.charAt(i);
if( ch == ´<´ ) {
buf.append( "<" );
}
else if( ch == ´>´ ) {
buf.append( ">" );
}
else {
buf.append( ch );
}
}
return buf.toString();
}
- 上一篇: JAVASERVER PAGE(JSP)简介
- 下一篇: JSP构架--2种方式
-= 资 源 教 程 =-
文 章 搜 索