2011-12-13 72 views
-2

am具有以下jsp標記以顯示數組列表值,zoneInformation包含[North, South, East, West]如何在jsp中爲dropdownlist設置值?

<html:form action="addcountry"> 
<%@ page import="java.util.List"%> 
<%@ page import="java.util.ArrayList"%> 
<html:select property="zone" styleClass="text ui-widget-content ui-corner-all">  
<% ArrayList ls = (ArrayList)request.getAttribute("zoneInformation"); 
for(int i=0;i<ls.size();i++){ 
%> 
<html:option value=" "><%=ls.get(i)%></html:option> 
<%}%> 
</html:select> 
</html:form> 

如何爲此下拉列表設置值....?

回答

0

首先,更喜歡JSTL:c:forEach而不是scrptlets。

然後,您可以將該值設置爲與顯示的標籤相同。

然後,您可以使用<html:options collection="${zoneInformation} />沒有任何循環。

0

html:select標記將使該選項具有與其屬性屬性值自動選擇相同的值。因此,在您的代碼中,將選擇值爲" "的區域信息。這意味着如果你想選擇一些選項,它的值應該等於表單bean的zone屬性。

而且請不要使用scriptlets。使用JSTL和EL。

+0

JSTL簡直太神奇了....!和mycode工作正常!感謝您的幫助! :-) – Manivannan

相關問題