在Struts 1.x中使用java设置select的默认值

Org*_*cat 6 java struts

我遇到过Struts 2.x的答案,但没有struts 1.x的答案.

我需要做的就是使用1.x的HTML:SELECT标签选择页面加载的默认值,该标签使用optioncollector:

<html:select property="status">
  <html:optionsCollection name="statusList" label="description" value="id" />
</html:select>
Run Code Online (Sandbox Code Playgroud)

看起来很简单,但我想避免使用javascript.

小智 11

您是否尝试标记使用该value属性<html:select>

<html:select property="status" value="...your status choise here...">
  <html:optionsCollection name="statusList" label="description" value="id" />
</html:select>
Run Code Online (Sandbox Code Playgroud)

  • @Organiccat:如果您使用的是[Struts EL标签](http://struts.apache.org/1.x/struts-el/index.html),那么您可以使用EL表达式,例如`$ {object.id} `.[JSP 2.0 with Struts base](http://www.webkaifa.com/jsp/jakartaStrutsCookbook/059600771x/jakartastrutsckbk-chp-3-sect-2.html)标签也是如此.如果上面两个都没有,那么我恐怕`<%= object.getId()%>`是唯一的方法 (2认同)