我想给下拉列表的元素值加空格,测试在Console System.out.println()正常,放到网页下拉列表里面,空格就没有了,不知道在下拉列表里面给name 值加空格怎么加?我的代码是
public String getFillName() {
String result = "";
if (node.length() > 1) {
// 填充空格
int fillLen = (node.length() - 1) / 3 * 2 + this.parentNode.length();
for (int i = 0; i < fillLen; i++) {
result += " ";//这里直接拼上空格,但网页里面显示不出来
}
result += "|____" + this.name;
} else {
result = this.name;
}
this.fillName = result;
return this.fillName;
}

解决方案 »

  1.   

    这个显示不了,早就试过了。
    直接就显示&nbsp;了。
      

  2.   


    你用什么显示的? el表达式?
    <c:out value="${参数}" escapeXml="false"/>试试这个!
      

  3.   

    我的是Struts
    我直接在我的程序里面控制的
    for (int i = 0; i < fillLen; i++) {
    result += "&nbsp;";
      

  4.   


    把这个result发到request里,
    <c:out value="${result}" escapeXml="false"/>
      

  5.   

    大哥,我可以在Struts里面写<c:out value="${result}" escapeXml="false"/>这个吗?我的for (int i = 0; i < fillLen; i++) {
    result += "&nbsp;";
    }代码 是写在pojo类里面的,我传过去的是整个对象,而且传过去的时候fillName字段的值是有空格的,只是在<select>里面显示不了,我在Eclipse里面测试过了,用Console输出看了。
      

  6.   

    搞定了,
    在页面写成下面的方式就可以了
    <bean:write name="dpData" property="fillName" filter="false"/><bean:write>标签用于在网页上输出某个Bean或它的属性的内容.其中它有一个filter属性,默认值为true.如果filter属性为true,将把输出内容中的特殊HTML符合作为普通字符串来显示;如果filter属性为false,则不会把输出内容中的热书HTML符号转化为普通字符串.谢谢woming66,让我联想到Struts标签的属性
      

  7.   


    客气了!!!
    <bean:write name="dpData" property="fillName" filter="false"/>
    <c:out value="${result}" escapeXml="false"/>
    效果是一样的!!