jsp简单自定义标签的forEach遍历及转义字符
2012-12-14 15:05:30 来源:WEB开发网核心提示:this.getJspContext().getOut().write(s);//写入浏览器}public String filter(String message) {//对字符串进行转义的方法if (message == null)return (null);char content[] = new char[m
this.getJspContext().getOut().write(s);//写入浏览器
}
public String filter(String message) {//对字符串进行转义的方法
if (message == null)
return (null);
char content[] = new char[message.length()];
message.getChars(0, message.length(), content, 0);
StringBuffer result = new StringBuffer(content.length + 50);
for (int i = 0; i < content.length; i++) {
switch (content[i]) {
case '<':
result.append("<");
break;
case '>':
result.append(">");
break;
case '&':
result.append("&");
break;
case '"':
result.append(""");
break;
default:
result.append(content[i]);
}
}
return (result.toString());
}
}
接下来就一样了,
<tag>
<name>htmlFilter</name>
<tag-class>com.csdn.items.HTMLFilter</tag-class>
<body-content>scriptless</body-content>
</tag>
<c:htmlFilter>
<a href=""> aaa</a>
</c:htmlFilter>
Jsp标签文件的内容原样输出;
}
public String filter(String message) {//对字符串进行转义的方法
if (message == null)
return (null);
char content[] = new char[message.length()];
message.getChars(0, message.length(), content, 0);
StringBuffer result = new StringBuffer(content.length + 50);
for (int i = 0; i < content.length; i++) {
switch (content[i]) {
case '<':
result.append("<");
break;
case '>':
result.append(">");
break;
case '&':
result.append("&");
break;
case '"':
result.append(""");
break;
default:
result.append(content[i]);
}
}
return (result.toString());
}
}
接下来就一样了,
<tag>
<name>htmlFilter</name>
<tag-class>com.csdn.items.HTMLFilter</tag-class>
<body-content>scriptless</body-content>
</tag>
<c:htmlFilter>
<a href=""> aaa</a>
</c:htmlFilter>
Jsp标签文件的内容原样输出;
更多精彩
赞助商链接