`
hyz301
  • 浏览: 373978 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

html:optionsCollection标签

 
阅读更多

1、html:optionsCollection标签生成多个HTML的option元素。该标签必须嵌在html:select标签中。它的功能和html:options标签的相同,但是它的name与property属性和其它标签的name与property属性意义一致,理解起来比较自然。

让我通过示例来介绍html:optionsCollection标签的用法。首先依据name="selectForm"和property="persons"取到selectForm中的persons列表,然后将列表中的对象(Person类型)的id属性作为option元素的value值(value="id"),将列表中的对象(Person类型)的name属性作为option元素的label值

(label="name")。

<html:select name="selectForm" property="person.id" size="1"> <html:optionsCollection name="selectForm" 
property="persons" label="name" value="id"/> </html:select>

 

bean中 private List resultList = new ArrayList();
public List getResultList() {
  return resultList;
 }
 public void setResultList(List resultList) {
  this.resultList = resultList;
 }
Action中newbean.setResultList(resultList);
jsp中<html:select name="assessForm" property="result" style="width:85%">
 <html:optionsCollection name="assessForm" property="resultList" value="value" label="label" />
    </html:select>

 

2、Action中request.setAttribute("RESOURCELIST",list);

bean中:无

jsp中<html:select name="roleForm" property="queryresid" onchange="selectonchange('querydesc', this.value)">
       <html:optionsCollection name="RESOURCELIST" value="id" label="name" />
 </html:select>

 注意:举例子:两个实体对象:zonghe 和shuini。zonghe的sn_id为shuini的主键。再设置property属性是一定要如下设置。还有在zongheForm中要有:

<html:select name="zongheForm" property="zonghe.shuini.snId">
	<html:optionsCollection label="snNumber" value="snId"
	                        name="zongheForm" property="shuiniList" />
</html:select>
 zongheForm部分代码:

 

        private Shuini shuini;
	private List<Shuini> shuiniList;
	public ZongheForm() {
		zonghe = new Zonghe();
		shuini = new Shuini();
		zonghe.setShuini(shuini);
	}
public Shuini getShuini() {
		return shuini;
	}

	public void setShuini(Shuini shuini) {
		this.shuini = shuini;
	}

	public List<Shuini> getShuiniList() {
		return shuiniList;
	}

	public void setShuiniList(List<Shuini> shuiniList) {
		this.shuiniList = shuiniList;
	}
 
分享到:
评论

相关推荐

    html optionsCollection标签使用

    ### HTML OptionsCollection 标签使用详解 #### 一、引言 在Web开发中,下拉列表是非常常见的交互元素之一,用于提供用户选择项。Struts框架中的`html:optionsCollection`标签允许开发者轻松地从Java集合中生成HTML...

    jsp中htmlselect标签的用法

    `jsp`中的`html:select`标签主要用于创建HTML表单中的下拉选择列表。这个标签在Struts框架中尤其常见,因为它与ActionForm对象的属性紧密关联,方便数据的提交和回显。以下是对`html:select`标签的详细解释和使用...

    JSP Struts之HTML标签库详解

    其中,HTML标签库是Struts中非常重要的一部分,它专门用于创建与Struts框架交互的HTML输入表单。 **HTML标签库** HTML标签库主要用于生成HTML元素,构建表单,以及展示错误信息。它分为三个主要类别: 1. **基本...

    Struts 中 Html 标签库 的用法(第二组标签,与Form相关的标签 ).rar

    6. `&lt;html:select&gt;`、`&lt;html:option&gt;`和`&lt;html:optionsCollection&gt;`标签:`&lt;html:select&gt;`创建下拉选择框`&lt;select&gt;`,`&lt;html:option&gt;`定义选择项,`&lt;html:optionsCollection&gt;`则可以方便地从ActionForm的集合属性中...

    最新的试题北大青鸟Y2

    10. Struts标签:在Struts中,使用html:optionsCollection标签可以初始化从数据库查询得到的下拉列表框选择项。 11. JSTL迭代标签:&lt;c:forEach&gt;的属性中,用于指定遍历对象集合的是value,选项c正确。 12. ASP.NET...

    strus标签总结及例子

    8. `html:select`、`html:option`和`html:optionsCollection`标签:用于创建下拉选择框。`&lt;html:select&gt;`定义选择框,`&lt;html:option&gt;`定义选项,而`&lt;html:optionsCollection&gt;`则可以基于集合动态生成选项。 9. `...

    Struts提供的和Form相关的标签 .rar

    6. `&lt;html:select&gt;`, `&lt;html:option&gt;`和`&lt;html:optionsCollection&gt;`标签:用于创建下拉选择框。例如: ```jsp &lt;html:select property="country"&gt; &lt;html:option value=""&gt;Select a country&lt;/html:option&gt; ...

    ACCP 5.0 Y2 考试题 200809

    7. **Struts**:在 Struts 应用中,html:optionsCollection 标签用于初始化下拉列表,其`value`属性表示将要显示的数据集合。 8. **MVC 设计模式**:在 JavaWeb 应用中,V(视图)通常由 JSP 页面充当,负责展示...

    struts html标签例子

    Struts HTML标签是Java开发Web应用时,特别是基于Apache Struts框架时常用的一类标签库。这些标签简化了HTML表单元素与ActionForm对象之间的交互,使得开发者可以更专注于业务逻辑,而不是繁琐的HTML代码。以下是...

    Struts标签文档

    5. `&lt;html:select&gt;`、`&lt;html:option&gt;`和`&lt;html:optionsCollection&gt;`:这些标签用于创建下拉选择框。`&lt;html:select&gt;`定义选择框,`&lt;html:option&gt;`添加单个选项,而`&lt;html:optionsCollection&gt;`则可以从ActionForm的...

    Struts标签库学习.rar

    第三部分,"Struts中的下拉列表标签的使用.doc"讲解了如何使用Struts的`&lt;html:select&gt;`、`&lt;html:option&gt;`和`&lt;html:optionsCollection&gt;`标签来创建下拉列表。这些标签允许开发者动态生成选项,可以绑定到ActionForm的...

    struts标签-HTML标签笔记

    下面详细介绍几种常用的HTML标签: ##### 2.1 `&lt;html:form&gt;` 标签 - **功能**:该标签用于定义HTML表单。 - **示例**: ```xml &lt;html:form action="/submit" method="post"&gt; ... &lt;/html:form&gt; ``` - **关键...

    北大青鸟的笔试试题最新

    【Struts框架】在Struts应用程序中,html:optionsCollection标签用于在JSP页面上创建下拉列表,它的value属性表示将要显示的数据集合。 【MVC设计模式】在JavaWeb应用中,MVC(Model-View-Controller)模式中的V...

    htmlSelect.txt

    以下是一段示例代码,用于解释如何使用上述标签: #### 实现步骤 1. **创建 Java Bean** (`Users` 类): ```java package com.pojo; public class Users { private String userName; private String userValue...

    Struts标签- HTML标签

    - `html:select`, `html:option`, `html:optionsCollection`: 处理下拉列表,可以动态加载选项数据。 - `html:link`: 创建链接,可以携带请求参数。 - `html:errors`: 显示验证错误,收集并显示所有表单验证失败...

    Struts1.2常见标签使用对学java的人有用

    #### HTML 类标签 1. **html:textproperty** - **语法**:`&lt;html:textproperty property="属性名" form="表单对象名"/&gt;` - **功能**:用于显示文本框,并设置其值为指定的表单对象中的属性值。 - **示例**: `...

    Struts标签库.chm是一个不错的东西

    - `&lt;html:select&gt;`、`&lt;html:option&gt;` 和 `&lt;html:optionsCollection&gt;`:用于创建下拉列表。 使用Struts标签库的好处在于: - **代码复用**:标签可以多次重复使用,减少代码量,提高开发效率。 - **增强可读性**:...

    StructTib.doc

    6. **`&lt;html:select&gt;`、`&lt;html:option&gt;`和`&lt;html:optionsCollection&gt;`标签**:用于创建下拉选择列表,`&lt;html:option&gt;`用于定义选项,`&lt;html:optionsCollection&gt;`则可以从数据库或其他集合中动态生成选项。...

    struts标签库使用

    - `&lt;html:select&gt;`,`&lt;html:option&gt;`和`&lt;html:optionsCollection&gt;`:用于创建下拉列表。 4. **数据校验** Struts标签库还可以与Validator框架结合,进行客户端和服务器端的数据校验。例如,可以使用`&lt;html:form&gt;`...

Global site tag (gtag.js) - Google Analytics