struts1中select下拉列表的使用
来源:互联网 发布:ar涂涂乐下载软件 编辑:程序博客网 时间:2024/06/05 17:51
Struts1中的单选下拉框简单实用像下面这样:
<html:form action="education" method="post">
<html:select property="education">
<html:options collection="edu2" property="value"
labelProperty="label"
/>
</html:select>
<html:submit value="submit"/>
</html:form>
<html:select>中education为你form文件中的一个property,存放你选中的值。
<html:options>是下拉列表选项,collection属性需要一个集合,比如arraylist,
vector。并且集合的元素都是一个bean。
1.你可以使用struts提供的LabelValueBean,直接
这样使用
<%
ArrayList alist=new ArrayList();
alist.add(new LabelValueBean("1","xiaoxue"));
alist.add(new LabelValueBean("2","chuzhong"));
alist.add(new LabelValueBean("3","gaozhong"));
request.setAttribute("edu2", alist);
%>
<html:options>中Property属性 和 labelProperty属性分别代表下拉框中的值(form中接收到的值)以及列表中显示出来的值,如果使用struts提供的LabelValueBean,你只需要写上value和label就可以了。像下面:
<html:form action="education" method="post">
<html:select property="education">
<html:options collection="edu2" property="value"
labelProperty="label"
/>
</html:select>
<html:submit value="submit"/>
</html:form>
2.也可以使用自定义的bean,像下面这样先自定义一个
public class Education {
private String id;
private String schoolName;
public Education(String id,String schoolName)
{
this.id=id;
this.schoolName=schoolName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSchoolName() {
return schoolName;
}
public void setSchoolName(String schoolName) {
this.schoolName = schoolName;
}
}
然后
<%
ArrayList alist=new ArrayList();
alist.add(new Education("1","xiaoxue"));
alist.add(new Education("2","chuzhong"));
alist.add(new Education("3","gaozhong"));
request.setAttribute("edu", alist);
%>
如果使用自定义的bean,填写bean中的字段名,像下面这样
<html:form action="education" method="post">
<html:select property="education">
<html:options collection="edu" property="id"
labelProperty="schoolName"
/>
</html:select>
<html:submit value="submit"/>
</html:form>
- struts1中select下拉列表的使用
- ‘select’的使用:下拉列表分组显示
- select下拉列表的级联
- select下拉列表的联动
- 在select下拉列表中显示查询的数据
- CSS3 中关于 select 下拉列表的样式
- CSS3 中关于 select 下拉列表的样式
- html 中可以自定义输入的 select 下拉列表
- s标签s:select下拉列表的使用
- s标签s:select下拉列表的使用
- struts2和struts1中select标签的使用
- struts1的用枚举类型做的select下拉框
- 下拉列表的使用
- JavaScript的Select下拉列表对象
- 设定select下拉列表的长度
- 动态增删select下拉列表的节点
- js取得select下拉列表的值
- select 下拉列表获取选中的文本
- 2.3-2
- MTD NAND OOB ECC 布局
- 华为透露成长秘诀:信息化建设铸就发展奇迹
- C++中流迭代器istream_iterator 和 ostream_iterator的使用
- 国内开放平台汇总
- struts1中select下拉列表的使用
- ios5兼容navigationBar背景问题
- Java并发(3)-中断线程
- vb study
- c++写的os,对于全局对象,构造函数不会执行
- VC 2008 Express下安装OpenCV2.3.1
- matlab里如何表示冲激信号
- 对泛滥的盗版软件的反思
- 【自由谈】城域网IPv6过渡技术——MAP技术(4)