---
title: "struts1 select标签"
author: "salute"
date: "2010-10-26T09:35:27Z"
tags: []
categories: ["企业架构"]
slug: "struts1-select"
draft: false
lastmod: "2010-10-26T09:35:27Z"
id: 793927
url: "https://salute.iteye.com/blog/793927"
---

```java


后台代码:

model层

   1. public List getMaterielttypeList() throws Exception{
   2.          List objList = new ArrayList();
   3.          MaterieltypeHome mtype = this.getMaterielTypeHome();
   4.          mtype.resetConditions();
   5.          mtype.setOrderbyclause("order by typename");
   6.          Collection mtypelist = mtype.findAll();
   7.          Iterator it = mtypelist.iterator();
   8.         while(it.hasNext()){
   9.             Materieltype obj = (Materieltype) it.next();
  10.            //固定写法，LabelValueBean()第一个参数为displayname，第二个参数为后台使用的值，一般为id。
  11.                     objList.add(new LabelValueBean(obj.getTypename(),String.valueOf(obj.getId())));
  12.          }
  13.         return objList;
  14.      }

Action代码

   1. //实例化model
   2. LldServices services = new LldServices(conn);
   3. //取出list并设置到request属性中。
   4. request.setAttribute("mtypelist", services.getMaterielttypeList());

表现层：

   1.


   2. <html:select property="typeid">
          <!--mtypelist为request中设置的属性值 labelProperty="label" property="value"固定写法-->
          <html:options collection="mtypelist" labelProperty="label" property="value" />
      </html:select>









```