<form:options itemValue="itemValue" itemLabel="itemLabel" items="items"/>
引數說明:public class Fans{ List fanList = new ArrayList(); //定義一個List集合 public List getFanList(){ //生成get和set方法 return fanList; } public void setFanList(List fanList){ this.fanList = fanList; } }
<%@page contentType="text/html" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <% com.Fans fanBean = new com.Fans(); List list = new ArrayList(); //定義一個List集合 list.add("周一");//為List集合新增資料 list.add("周二"); list.add("周三"); list.add("周四"); list.add("周五"); fanBean.setFanList(list); //把集合儲存到Fans物件中 request.setAttribute("command",fanBean); //把Fans物件儲存到request中 %> <form:form> 計劃完成日期在本週的: <form:select path = "fanList"multiple="false"> <form:options items = "${command.fanList}"/> </form:select> </form:form>
public class Fans{ Map fanMap; //定義一個Map集合 public Map getFanMap(){ //生成get和set方法 return fanMap; } public void setFanMap(Map fanMap){ this.fanMap = fanMap; } }
<%@page contentType="text/html" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <% com.Fans fanBean = new com.Fans(); Map map = new TreeMap(); //定義一個Map集合 map.put("1","周一"); //為Map集合新增資料 map.put("3","周三"); map.put("5","周五"); map.put("7","周日"); fanBean.setFanMap(map); //把集合儲存到Fans物件中 request.setAttribute("command",fanBean); //把Fans物件儲存到request中 %> <form:form> 下次招聘時間定在本週的: <form:select path="fanMap" multiple="false"> <form:options items="${command.fanMap}"/> </form:select> </form:form>