jsp标签

目录

一、foreach标签

 二、select标签


一、foreach标签

代码展示:

建一个助手类:

package com.cdl.tag;

import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

/**
 * <c:forEach items="${clas12}" var="c">
 * 分析会有两个属性:
 * items:List<object>
 * var:String
 * 分析线路返回值:
 * 第二条线路:eval_body_include
 * 第三条线路:eval_body_again
 * @author 陈冬丽
 *
 */
public class ForeachTag extends BodyTagSupport{
	private String var;
	private List<Object> items;
	
	public String getVar() {
		return var;
	}
	public void setVar(String var) {
		this.var = var;
	}
	public List<Object> getItems() {
		return items;
	}
	public void setItems(List<Object> items) {
		this.items = items;
	}
	
	
	@Override
	public int doStartTag() throws JspException {
		Iterator<Object> it = items.iterator();
//		<option value="where cid='${c.cid}'">${c.cname}</option>
//		var = c; it.next()是集合中的某一个对象
//		pageContext.setAttribute("c", items.get(0));
		pageContext.setAttribute(var, it.next());
		pageContext.setAttribute("it", it);//遍历到第几个位置就在第几个位置 并不是在初始位置(为了保留迭代时指针器的位置)
		return EVAL_BODY_INCLUDE;
	}
	
	@Override
	public int doAfterBody() throws JspException {
		Iterator<Object> it = (Iterator<Object>)pageContext.getAttribute("it");
		if(it.hasNext()) {
			pageContext.setAttribute(var, it.next());
			pageContext.setAttribute("it", it);
			return EVAL_BODY_AGAIN;
		}
		else {
			return EVAL_PAGE;
		}
	}
	
	
}

进去tld配置文件中配置

<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    
  <description>JSTL 1.1 core library</description>
  <display-name>JSTL core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>z</short-name>
  <uri>http://jsp.veryedu.cn</uri>

  <validator>
    <description>
        Provides core validation features for JSTL tags.
    </description>
    <validator-class>
        org.apache.taglibs.standard.tlv.JstlCoreTLV
    </validator-class>
  </validator>

  <!-- <tag>
   代表标签库标签的名字
    <name>demo1</name>
    代表该标签对应的助手类的全路径名
    <tag-class>com.cdl.tag.DemoTag1</tag-class>
    代表是一个jsp标签
    <body-content>JSP</body-content>
     <attribute>
    该自定义标签的属性名称
        <name>var</name>
        该属性是否必填
        <required>false</required>
        该属性值是否支持表达式
        <rtexprvalue>false</rtexprvalue>
    </attribute> 
  </tag> -->
  
  
  <tag>
    <name>if</name>
    <tag-class>com.cdl.tag.IfTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>test</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>

	
	<tag>
    <name>set</name>
    <tag-class>com.cdl.tag.SetTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute> 
    <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>
	

 <tag>
    <name>out</name>
    <tag-class>com.cdl.tag.OutTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>
  
  
  
  <tag>
    <name>for</name>
    <tag-class>com.cdl.tag.ForeachTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>items</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
    <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>
	
	

</taglib>

建实体类

package com.cdl.entity;

public class Teacher {
	private String tid;
	private String name;
	public String getTid() {
		return tid;
	}
	public void setTid(String tid) {
		this.tid = tid;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public Teacher() {
		// TODO Auto-generated constructor stub
	}
	public Teacher(String tid, String name) {
		this.tid = tid;
		this.name = name;
	}
	
	
}

到页面运行

<%@page import="java.util.ArrayList"%>
<%@page import="com.cdl.entity.Teacher"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://jsp.veryedu.cn"  prefix="z"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 1、有标签体的情况下 默认会调用助手类的doStartTag,doAfterBody,doEndTag方法
	 2、如果将doStartTag的返回值改为skip_body,那么doAfterBody就不会调用执行
	 3、如果如果将doStartTag的返回值改为EVAL_BODY_INCLUDE,那么doAfterBody就不会调用执行
	 4、如果如果将doAfterBody的返回值改为EVAL_BODY_AGAIN,那么就会死循环
-->
	<%-- <z:demo1>xx</z:demo1> --%>
	<%-- <z:if test="true">true</z:if>
	<z:if test="false">false</z:if>
	<z:set var="name" value="laoliu"></z:set>
	<z:out value="${name}"></z:out> --%>
	
	<% 
		List<Teacher> list = new ArrayList<Teacher>();
		list.add(new Teacher("t001","张三"));
		list.add(new Teacher("t002","李四"));
		list.add(new Teacher("t003","老六"));
		request.setAttribute("list", list);
		
	%>
	<z:for items="${list}" var="t">
		${t.tid}:${t.name}
	</z:for>
	
</body>
</html>

运行结果:

 二、select标签

目标需求:

1.省略遍历的过程

2.当做数据回显时,无需增加if判断,无需增加新的代码

建一个助手类

package com.cdl.tag;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.sun.org.apache.xml.internal.serializer.ToHTMLSAXHandler;

/**
 * 1.省略遍历的过程
 * 	<z:select></select>
 * 2.做数据回显时,无需增加if判断,无需增加增加新的代码
 * <option value="where cid='${c.cid}'">${c.cname}</option>
 * 
 * 分析:
 * 		1.后台要遍历->数据源->items
 * 		2.需要一个对象的属性代表下拉框对应的展示内容->textVal
 * 		3.需要一个对象的属性代表下拉框对应的value值->textKey
 * 		4.默认的头部选项展示内容->headerTextVal
 * 		5.默认的头部选项值->headerTextKey
 * 		6.数据中存贮的值,为了方便做数据回显->selectedVal
 * 		7.id
 * 		8.name
 * 		9.cssStyle...
 * @author 陈冬丽
 *
 */
public class SelectTag extends BodyTagSupport{
	private List<Object> items;
	private String textVal;//teachername
	private String textKey;//value
	private String headerTextVal;
	private String headerTextKey;
	private String selectedVal;
	private String id;
	private String name;
	
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		try {
			out.print(ToHTML());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doStartTag();
	}
	
	
	private String ToHTML() {
		StringBuffer sb = new StringBuffer();
		sb.append("select id='' name=''");
		sb.append("<option value='1'>zhangsan</option>");
		sb.append("<option value='2'>lisi</option>");
		sb.append("</select>");
		return sb.toString();
	}


	public List<Object> getItems() {
		return items;
	}
	public void setItems(List<Object> items) {
		this.items = items;
	}
	public String getTextVal() {
		return textVal;
	}
	public void setTextVal(String textVal) {
		this.textVal = textVal;
	}
	public String getTextKey() {
		return textKey;
	}
	public void setTextKey(String textKey) {
		this.textKey = textKey;
	}
	public String getHeaderTextVal() {
		return headerTextVal;
	}
	public void setHeaderTextVal(String headerTextVal) {
		this.headerTextVal = headerTextVal;
	}
	public String getHeaderTextKey() {
		return headerTextKey;
	}
	public void setHeaderTextKey(String headerTextKey) {
		this.headerTextKey = headerTextKey;
	}
	public String getSelectedVal() {
		return selectedVal;
	}
	public void setSelectedVal(String selectedVal) {
		this.selectedVal = selectedVal;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	
	
}

配置文件

<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    
  <description>JSTL 1.1 core library</description>
  <display-name>JSTL core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>z</short-name>
  <uri>http://jsp.veryedu.cn</uri>

  <validator>
    <description>
        Provides core validation features for JSTL tags.
    </description>
    <validator-class>
        org.apache.taglibs.standard.tlv.JstlCoreTLV
    </validator-class>
  </validator>

  <!-- <tag>
   代表标签库标签的名字
    <name>demo1</name>
    代表该标签对应的助手类的全路径名
    <tag-class>com.cdl.tag.DemoTag1</tag-class>
    代表是一个jsp标签
    <body-content>JSP</body-content>
     <attribute>
    该自定义标签的属性名称
        <name>var</name>
        该属性是否必填
        <required>false</required>
        该属性值是否支持表达式
        <rtexprvalue>false</rtexprvalue>
    </attribute> 
  </tag> -->
  
  
  <tag>
    <name>if</name>
    <tag-class>com.cdl.tag.IfTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>test</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>

	
	<tag>
    <name>set</name>
    <tag-class>com.cdl.tag.SetTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute> 
    <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>
	

 <tag>
    <name>out</name>
    <tag-class>com.cdl.tag.OutTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>
  
  
  
  <tag>
    <name>for</name>
    <tag-class>com.cdl.tag.ForeachTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>items</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
    <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>
  
  
  <tag>
    <name>select</name>
    <tag-class>com.cdl.tag.SelectTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>items</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
    <attribute>
        <name>textVal</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>textKey</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
     <attribute>
        <name>headerTextVal</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>headerTextKey</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>selectedVal</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
        <name>id</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>name</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>
  
	
	

</taglib>

界面:

<%@page import="java.util.ArrayList"%>
<%@page import="com.cdl.entity.Teacher"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://jsp.veryedu.cn"  prefix="z"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 1、有标签体的情况下 默认会调用助手类的doStartTag,doAfterBody,doEndTag方法
	 2、如果将doStartTag的返回值改为skip_body,那么doAfterBody就不会调用执行
	 3、如果如果将doStartTag的返回值改为EVAL_BODY_INCLUDE,那么doAfterBody就不会调用执行
	 4、如果如果将doAfterBody的返回值改为EVAL_BODY_AGAIN,那么就会死循环
-->
	<%-- <z:demo1>xx</z:demo1> --%>
	<%-- <z:if test="true">true</z:if>
	<z:if test="false">false</z:if>
	<z:set var="name" value="laoliu"></z:set>
	<z:out value="${name}"></z:out> --%>
	
	<% 
		List<Teacher> list = new ArrayList<Teacher>();
		list.add(new Teacher("t001","张三"));
		list.add(new Teacher("t002","李四"));
		list.add(new Teacher("t003","老六"));
		request.setAttribute("list", list);
		
	%>
	<z:for items="${list}" var="t">
		${t.tid}:${t.name}
	</z:for>
	
	<select>
		<option value="1">zhangsan</option>
		<option value="2">lisi</option>
	</select>
	<%-- <z:select></z:select> --%>
	
</body>
</html>

运行结果:

 优化的显示结果:

回显前

 代码:

package com.cdl.tag;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.beanutils.PropertyUtils;

import com.sun.org.apache.xml.internal.serializer.ToHTMLSAXHandler;

/**
 * 1.省略遍历的过程
 * 	<z:select></select>
 * 2.做数据回显时,无需增加if判断,无需增加增加新的代码
 * <option value="where cid='${c.cid}'">${c.cname}</option>
 * 
 * 分析:
 * 		1.后台要遍历->数据源->items
 * 		2.需要一个对象的属性代表下拉框对应的展示内容->textVal
 * 		3.需要一个对象的属性代表下拉框对应的value值->textKey
 * 		4.默认的头部选项展示内容->headerTextVal
 * 		5.默认的头部选项值->headerTextKey
 * 		6.数据中存贮的值,为了方便做数据回显->selectedVal
 * 		7.id
 * 		8.name
 * 		9.cssStyle...
 * @author 陈冬丽
 *
 */
public class SelectTag extends BodyTagSupport{
	private List<Object> items;
	private String textVal;//teachername
	private String textKey;//value
	private String headerTextVal;
	private String headerTextKey;
	private String selectedVal;
	private String id;
	private String name;
	
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
			try {
				out.print(ToHTML());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return super.doStartTag();
	}
	
	
	private String ToHTML() throws Exception{
		StringBuffer sb = new StringBuffer();
		sb.append("<select id='"+id+"' name='"+name+"' >");
		if(headerTextVal !=null && !"".equals(headerTextVal)) {
			sb.append("<option value='"+headerTextKey+"'>"+headerTextVal+"</option>");
		}
		for (Object obj : items) {
//			<z:select textVal="name" items="${list}" textKey="tid"></z:select> 
			Field textKeyFiled = obj.getClass().getDeclaredField(textKey);
			textKeyFiled.setAccessible(true);
			Object value = textKeyFiled.get(obj);//真正下拉框展示值
			
			if(selectedVal!=null && !"".equals(selectedVal)&&selectedVal.equals(value)) {
				sb.append("<option  selected value='"+value+"'>"+PropertyUtils.getProperty(obj,textVal)+"</option>");
			}
			else {
				sb.append("<option value='"+value+"'>"+PropertyUtils.getProperty(obj,textVal)+"</option>");
			}
			
		}
		sb.append("</select>");
		return sb.toString();
	}


	public List<Object> getItems() {
		return items;
	}
	public void setItems(List<Object> items) {
		this.items = items;
	}
	public String getTextVal() {
		return textVal;
	}
	public void setTextVal(String textVal) {
		this.textVal = textVal;
	}
	public String getTextKey() {
		return textKey;
	}
	public void setTextKey(String textKey) {
		this.textKey = textKey;
	}
	public String getHeaderTextVal() {
		return headerTextVal;
	}
	public void setHeaderTextVal(String headerTextVal) {
		this.headerTextVal = headerTextVal;
	}
	public String getHeaderTextKey() {
		return headerTextKey;
	}
	public void setHeaderTextKey(String headerTextKey) {
		this.headerTextKey = headerTextKey;
	}
	public String getSelectedVal() {
		return selectedVal;
	}
	public void setSelectedVal(String selectedVal) {
		this.selectedVal = selectedVal;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	
	
}
<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    
  <description>JSTL 1.1 core library</description>
  <display-name>JSTL core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>z</short-name>
  <uri>http://jsp.veryedu.cn</uri>

  <validator>
    <description>
        Provides core validation features for JSTL tags.
    </description>
    <validator-class>
        org.apache.taglibs.standard.tlv.JstlCoreTLV
    </validator-class>
  </validator>

  <!-- <tag>
   代表标签库标签的名字
    <name>demo1</name>
    代表该标签对应的助手类的全路径名
    <tag-class>com.cdl.tag.DemoTag1</tag-class>
    代表是一个jsp标签
    <body-content>JSP</body-content>
     <attribute>
    该自定义标签的属性名称
        <name>var</name>
        该属性是否必填
        <required>false</required>
        该属性值是否支持表达式
        <rtexprvalue>false</rtexprvalue>
    </attribute> 
  </tag> -->
  
  
  <tag>
    <name>if</name>
    <tag-class>com.cdl.tag.IfTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>test</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>

	
	<tag>
    <name>set</name>
    <tag-class>com.cdl.tag.SetTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute> 
    <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>
	

 <tag>
    <name>out</name>
    <tag-class>com.cdl.tag.OutTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
  </tag>
  
  
  
  <tag>
    <name>for</name>
    <tag-class>com.cdl.tag.ForeachTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>items</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
    <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>
  
  
  <tag>
    <name>select</name>
    <tag-class>com.cdl.tag.SelectTag</tag-class>
    <body-content>JSP</body-content>
     <attribute>
        <name>items</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute> 
    <attribute>
        <name>textVal</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>textKey</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
     <attribute>
        <name>headerTextVal</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>headerTextKey</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>selectedVal</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
        <name>id</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>name</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>
  
	
	

</taglib>

界面:

<%@page import="java.util.ArrayList"%>
<%@page import="com.cdl.entity.Teacher"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://jsp.veryedu.cn"  prefix="z"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 1、有标签体的情况下 默认会调用助手类的doStartTag,doAfterBody,doEndTag方法
	 2、如果将doStartTag的返回值改为skip_body,那么doAfterBody就不会调用执行
	 3、如果如果将doStartTag的返回值改为EVAL_BODY_INCLUDE,那么doAfterBody就不会调用执行
	 4、如果如果将doAfterBody的返回值改为EVAL_BODY_AGAIN,那么就会死循环
-->
	<%-- <z:demo1>xx</z:demo1> --%>
	<%-- <z:if test="true">true</z:if>
	<z:if test="false">false</z:if>
	<z:set var="name" value="laoliu"></z:set>
	<z:out value="${name}"></z:out> --%>
	
	<% 
		List<Teacher> list = new ArrayList<Teacher>();
		list.add(new Teacher("t001","张三"));
		list.add(new Teacher("t002","李四"));
		list.add(new Teacher("t003","老六"));
		request.setAttribute("list", list);
		
	%>
	<z:for items="${list}" var="t">
		${t.tid}:${t.name}
	</z:for>
	
	<select id="" name="">
		<option value="1">zhangsan</option>
		<option value="2">lisi</option>
	</select>
	
	<z:select selectedVal="t002" headerTextKey="-1" headerTextVal="======请选择====" textVal="name" items="${list}" textKey="tid"></z:select>
	
</body>
</html>

回显后:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值