struts模式下设置html:select初始值

本文介绍如何在Struts2框架中使用html:select标签正确地设置默认选中的选项。不同于HTML中的select标签,Struts2中的设置需要在html:select标签内直接指定默认值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 使用html:select标签,不能像在html中使用select标签一样,只在<option></option> 中设置selected就可以设置默认值。而应该在<html:select>中来设。如:

<html:select property="discountType"  value="2" onchange="showPage(discountType)" >
          <html:option value="1"><bean:message key="discountType.holiday" /></html:option>
          <html:option value="2"><bean:message key="discountType.week" /></html:option>
          <html:option value="3"><bean:message key="discountType.date" /></html:option>
         </html:select>

加上:value="**",这样就可以将其初始值设为2,页面则显示其对应的信息<bean:message key="discountType.week" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值