---
title: "带下拉框的数据编辑页面"
author: "ccj"
date: "2007-09-22T11:45:48Z"
tags: []
categories: ["企业架构"]
slug: "untitled"
draft: false
lastmod: "2007-09-22T11:45:48Z"
id: 126137
url: "https://ccj.iteye.com/blog/126137"
---

要求的数据编辑页面如下


编号
分类 （下拉框）  
商品名称
普通会员价
高级会员价
.
.
.


在Action中分别将数据对象merchform和分类list存入

```

merch = mr.get(merid);
if(merch.getMerId()>0)
{	
  request.setAttribute("editMerchForm",merch);
  ClassifyManager cr = ClassifyManagerImpl.getInstance();
  List list = cr.query();
  if(list.size()!=0)
  {
    //save to session
    request.getSession().setAttribute("list", list);
  }
}
....

```



在JSP中无法使用html标签来显示list，因此只有如此


```

<logic:present name="editMerchForm">
  <html:form method="post" action="/editMerch">
    <table border="0" align="center" cellpadding="5" cellspacing="0">
      <tr>
        <td>编号</td>
        <td>显示数据</td>
        <td>验证时错误信息</td>
      </tr>
      <tr>
        <td>分类</td>
        <td>
        <bean:define id="cid" name="editMerchForm" property="classify.claId">

        <!-- 此处如果使用html:select则可以自动实现选中，但必须把list存入form中才行 -->
        <select name="claId">
          <logic:iterate id="sele" name="list">
          <bean:define id="claid" name="sele" property="claId"/>
          <option value="<%=claid %>"
            <%if (cid.equals(claid)){ out.print("selected");}%>/>
          <bean:write name="sele" property="claName" /> 
          </option>
          </logic:iterate>
        </select>
        </td>
        <td><html:error/></td>
      </tr>
      <tr>
        <td>商品名称</td>
        <td><html:text name="editMerchForm" property="merName"></html:text></td>
        <td><html:errors/></td>
      </tr>

```


想问问大家，有没有更方便快捷的办法。如果说可以将list存入form中，再从JSP中读出显示，请给出存入和读取的代码，谢谢。