jsp - 在struts1.2中如何根据数据库值填充下拉列表

标签 jsp listbox jsp-tags struts-1

我有一个文本框和一个 html 下拉列表,单击“保存”按钮后,其值将保存到数据库中,但在搜索该值时,除以下下拉列表外,所有文本框和单选按钮都会被填充..

      <td align= "right" nowrap> 
                            <html:select property="standard">

                                <html:option value="I">I</html:option>

                                <html:option value="II">II</html:option>

                                <html:option value="III">III</html:option> ...

为了填充值,我使用以下代码..

        stuform.setStandard((String)tempmap.get("STANDARD"));

注意:我已经检查过 Stuform.getStandard() 值是否存在,但它没有显示在 jsp 上。

最佳答案

下拉列表应由表单类中的 LabelValueBean 对象列表表示,如下所示。

List<LabelValueBean> listOfStandards = new ArrayList<LabelValueBean>();
//popoulate the list
myForm.setStandardList(listOfStandards);

在您的 jsp 中,您可以访问下拉列表中的列表,如下所示:

<html:select property="standard" styleId="standard">
    <html:optionsCollection name="myForm" property="standardList" label="label" value="value"  />
</html:select>

注意:确保您的表单中有一个“标准”属性。 “标准”属性将使用下拉列表中所选项目的值进行设置。

关于jsp - 在struts1.2中如何根据数据库值填充下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17273849/

相关文章:

javascript - 如何将参数传递给表单标签外部定义的javascript函数?

mysql - 无法使用jsp页面连接到mysql数据库,但出现以下错误java.sql.SQLException : No suitable driver found jdbc:mysql://localhost:3306/dbname

c# - 如何使 ItemTemplate 的 DataTemplate 中的网格自动调整为 ListBox 宽度?

jquery - 是否可以使用 jQuery 选择器来访问 Struts2 元素而不需要插件?

c# - 将多个列表框项目添加到数据库

c# - 检测鼠标点击是否命中不在列表框中的项目 [C#]

用于嵌套树结构的 Java JSP 自定义标记。

java - 如何创建将字段标记为只读的 JSP 自定义标记?

Eclipse 索引需要很长时间

jsp - SSL 连接适用于控制台应用程序但不适用于 Glassfish