---
title: "【转】bean:write 中filter的作用 "
author: "lasombra"
date: "2012-10-22T14:41:10Z"
tags: ["Struts"]
categories: ["Web前端"]
slug: "bean-write-filter"
draft: false
lastmod: "2012-10-22T14:41:10Z"
id: 1702999
url: "https://lasombra.iteye.com/blog/1702999"
---

STRUTS的标签有一个 filter 属性，默认值为true。如果 filter 为true，将把输出内容中的特殊HTML符号作为普通字符串来显示；如果 filter 属性为false，则不会把输出内容中的特殊HTML符号转化为普通字符串。例如: &lt;% String boldStart="**"; String boldEnd="**"; request.serAttribute("bs",boldStart); request.serAttribute("be",boldEnd); %&gt; This should not be in bold  
This should be in bold 以上代码先定义了两个 request 范围内的变量 bs 和 be，它们得知分别为"**"和"**"。在HTML语言中，"**"和"**"为粗体字的标记。第一组标签没有设置filter属性，将采用它的默认值true，此时"**"和"**"作为普通文本，因此输出内容为: This should not be in **bold** 第一组标签的filter属性为false，此时"**"和"**"作为html的粗体字的标记来处理，因此输出内容为: This should not be in bold