[英]Java -Struts 1.2 combobox question
我正在使用java(Struts 1.2)。 我的第一頁是登錄頁面。 成功登錄后,將顯示第二頁。第二頁包含一個表單,其中一個字段是一個組合框。 我希望此組合框應填充,以便用戶可以選擇該選項。
我嘗試了許多方法,例如使用html:options集合和html:optionsCollections等。但是它顯示了諸如未找到bean之類的錯誤。
誰能給我一個示例工作代碼。
謝謝
<%
List< LabelValueBean> hourList = new ArrayList<LabelValueBean>();
pageContext.setAttribute("hourList", hourList);
%>
<html:select property="endhour">
<html:options collection="hourList" property="value" labelProperty="label" />
<html:select>
html:select上的屬性是表單中的屬性,當用戶從組合框中選擇某些內容時,該屬性將被填充。
---很抱歉,無法格式化它以清楚顯示代碼
必須在html:form中使用html標記,並且兩者都必須具有關聯的bean,您可以在struts.xml中對其進行配置。
<form-beans>
<form-bean name="LoginForm"
type="struts.forms.LoginForm" />
</form-beans>
<action name="LoginForm" path="/logon" type="common.Logon"
parameter="cmd">
<forward name="error" path="/html/login/login.jsp?login_error=1" />
<forward name="success" path="/login.do" />
</action>
我能告訴你的是:
LoginAction
),讓您的操作前進到另一個將填充您的列表的操作。 request.setAttribute("contents", list)
將頁面轉發到JSP文件。 contents
(存儲在request.setAttribute
方法中),並執行以下操作: 例:
<html:select property="selectedValue">
<html:options name="contents" />
</html:select>
有關Struts HTML TagLib的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.