剛開始為如下代碼:
- <html:select name="ShuiwujiguanForm" property="swjg_dmSelect" >
- <option value=""></option>
- <html:options collection="select_list" property="swjg_dm" labelProperty="swjg_mc"/>
- </html:select>
需要改為按樹級分層的結構,如下圖:
代碼修改為:
- <html:select name="ShuiwujiguanForm" property="swjg_dmSelect" >
- <option value=""></option>
- <logic:iterate id="select_list" name="ShuiwujiguanForm" property="select_list" scope="request">
- <option value="<bean:write name="select_list" property="swjg_dm"/>">
- <logic:equal name="select_list" property="swjg_level" value="1">nbsp;nbsp;</logic:equal>
- <logic:equal name="select_list" property="swjg_level" value="2">nbsp;nbsp;nbsp;nbsp;</logic:equal>
- <logic:equal name="select_list" property="swjg_level" value="3">nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;</logic:equal>
- <logic:equal name="select_list" property="swjg_level" value="4">nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; </logic:equal>
- <bean:write name="select_list" property="swjg_mc"/>
- </option>
- </logic:iterate>
- </html:select>
nbsp;替換為 ,在這里 不顯示
logic:equal 進行判斷, 級別為1的進行空格,為2的再多空格,依次類推。
logic:iterate用法
id 腳本變量的名稱,它保存著集合中當前元素的句柄。
name 代表了你需要疊代的集合(不知道和property有啥區(qū)別),來自session或者request的屬性。
type 是其中的集合類元素的類型
1、name和property都存在的時候有值
- <logic:iterate id="select_list" name="ShuiwujiguanForm" property="select_list" scope="request">
- </logic:iterate>
遍歷的是property="select_list"的值
2、有property無name時報錯
- <logic:iterate id="select_list " property="select_list" scope="request">
- </logic:iterate>
3、有name無property時有值
- <logic:iterate id=" select_list " name="select_list" scope="request">
- </logic:iterate>
遍歷的是 name ="select_list"的值
id保存著集合中當前元素,可隨意取值 但iterator標簽內的標簽一些name屬性就要引用這個id值
例如id取值為a:
- <logic:iterate id="a" name="ShuiwujiguanForm" property="select_list" scope="request">
- <option value="<bean:write name="a" property="swjg_dm"/>">
- <logic:equal name="a" property="swjg_level" value="1">nbsp;nbsp;</logic:equal>
- <bean:write name="a" property="swjg_mc"/>
- </option>
- </logic:iterate>
bean:write用法
bean:write常用的屬性有如下幾個:
1、name,用來指定屬性的名字
2、filter,用來指定是否屏蔽到屬性值的HTML格式
3、property,用來指定name所代表的對象的屬性名字
4、format,用來指定顯示的時間,數(shù)字,日期等的格式
只介紹name與property屬性
例1
action中設置了request.setAttribute("hello","hello world");
則在jsp頁面中,用struts的write標簽取出并顯示的方式如下:
<bean:write name="hello"/>,則頁面上顯示出hello world。
例2
假如有User類和Dept類,User類有屬性名字userName,年齡age,和所屬的Dept,
Dept類有屬性組名deptName,并均具有相應的get和set方法。
某處設置了request.setAttribute("user",new User("張三","23","男",new Dept("開發(fā)部")));
則在某個jsp頁面中,用struts的write標簽取出并按指定方式顯示結構體的方法如下:
- 用戶名:<input type="text" value="<bean:write name="user" property="userName"/>">
- 年齡:<input type="text" value="<bean:write name="user" property="age"/>">
- 性別:<input type="text" value="<bean:write name="user" property="sex"/>">
- 組名:<input type="text" value="<bean:write name="user" property="dept.deptName"/>">
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請
點擊舉報。