`

【转】bean:write 中filter的作用

    博客分类:
  • Java
阅读更多

STRUTS的<bean:write>标签有一个 filter 属性,默认值为true。如果 filter 为true,将把输出内容中的特殊HTML符号作为普通字符串来显示;如果 filter 属性为false,则不会把输出内容中的特殊HTML符号转化为普通字符串。例如:
<%
  String boldStart="<B>";
  String boldEnd="</B>";
  request.serAttribute("bs",boldStart);
  request.serAttribute("be",boldEnd);
%>

This should not be in <bean:write name="bs">bold<bean:write name="be"/></BR>
This should be in <bean:write name="bs" filter="false">bold<bean:write name="be" filter="false"/>

以上代码先定义了两个 request 范围内的变量 bs 和 be,它们得知分别为"<B>"和"</B>"。在HTML语言中,"<B>"和"</B>"为粗体字的标记。第一组<bean:write>标签没有设置filter属性,将采用它的默认值true,此时"<B>"和"</B>"作为普通文本,因此输出内容为:

  This should not be in <B>bold</B>

第一组<bean:write>标签的filter属性为false,此时"<B>"和"</B>"作为html的粗体字的标记来处理,因此输出内容为:

  This should not be in bold
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics