今天做系统的时候遇到一个问题,需要把session中的某个字符串打印出来。
我用的是<bean:write/>标签。刚开始在jsp页面输出了整字符串。
比如。session中
String selectStr = "<select name='contract_type'><optgroup label='contract_name'><option value='contract_code'>contract_name</option></optgroup></select>";
set 到session中
request.getSession().setAttribute("select", selectStr);
在jsp页面
<bean:write name="select" filter="false"/>
说明:如果filter设置为true,属性中的所有特殊HTML字符都将被转化为相应的实体引用,即原样输出:
<select name='contract_type'><optgroup label='contract_name'><option value='contract_code'>contract_name</option></optgroup></select>
;设置为false时,bean:write才会将来要打印的字符串中的特殊字符自动转换html的标签.