Springweb < form: Options > tab: defines multiple options for a drop-down selection box or list box
•
Java
Example 1
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>
Example 2
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>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码