zoukankan      html  css  js  c++  java
  • struts1 logic:iterate bean:write标签使用

    只是截取项目中部分代码,供参考及日后查阅

    用struts1标签html:select 展现select下拉列表
    刚开始为如下代码:
    <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;替换为&nbsp;,在这里&nbsp;不显示
    logic:equal 进行判断, 级别为1的进行空格,为2的再多空格,依次类推。


    logic:iterate用法
    id 脚本变量的名称,它保存着集合中当前元素的句柄。 
    name 代表了你需要叠代的集合(不知道和property有啥区别),来自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,用来指定显示的时间,数字,日期等的格式

    只介绍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("开发部")));
    则在某个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"/>">


  • 相关阅读:
    live555学习之RTSP连接建立以及请求消息处理过程
    RTSP协议学习笔记
    RTP头结构解析
    Doubango ims 框架 分析之 多媒体部分
    VMware虚拟机 NAT模式 配置静态ip
    计算机网络: IP地址,子网掩码,网段表示法,默认网关,DNS服务器详解
    VMWare VMNet 8 的配置使用
    VMware虚拟机CentOS7
    如何禁止虚拟机自动获取DHCP分配的ip地址
    Linux之VMware虚拟机取消DHCP
  • 原文地址:https://www.cnblogs.com/itmyhome/p/4131379.html
Copyright © 2011-2022 走看看