定义有标签体的标签库

实例

标签处理类----AttributeTag.java

package org.tagdemo ;
import java.io.* ;
import javax.servlet.jsp.* ;
import javax.servlet.jsp.tagext.* ;

public class AttributeTag extends TagSupport {
	private String name ;	// 接收属性的名称
	private String scope ;	// 接收属性的范围
	
	public int doStartTag()
               throws JspException{	// 是判断属性是否存在
		Object value = null ;
		if("page".equals(this.scope)){	// 是否是page范围
			value = super.pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE) ;
		}
		if("request".equals(this.scope)){	// 是否是request范围
			value = super.pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE) ;
		}
		if("session".equals(this.scope)){	// 是否是session范围
			value = super.pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE) ;
		}
		if("application".equals(this.scope)){	// 是否是request范围
			value = super.pageContext.getAttribute(this.name,PageContext.APPLICATION_SCOPE) ;
		}
		if(value == null){	// 表示现在根本就没有此属性
			return TagSupport.SKIP_BODY ;	// 没有属性不执行标签体
		} else {
			return TagSupport.EVAL_BODY_INCLUDE ;	// 执行标签体
		}
	}

	public void setName(String name){
		this.name = name ;
	}
	public void setScope(String scope){
		this.scope = scope ;
	}
	public String getName(){
		return this.name ;
	}
	public String getScope(){
		return this.scope ;
	}
}
定义标签描述文件----/WEB-INF/tag.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_1.xsd"
    version="2.1">
    <tlib-version>1.0</tlib-version>
    <short-name>mldntag</short-name>
    <tag>
	<name>present</name>
	<tag-class>org.tagdemo.AttributeTag</tag-class>
	<body-content>JSP</body-content>
	<attribute>
		<name>name</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
	<attribute>
		<name>scope</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
    </tag>
</taglib>
配置web.xml,设置映射名称

	<jsp-config>
		<taglib>
			<taglib-uri>mldn_date</taglib-uri>
			<taglib-location>/WEB-INF/datetag.tld</taglib-location>
		</taglib>
		<taglib>
			<taglib-uri>mldn</taglib-uri>
			<taglib-location>/WEB-INF/tag.tld</taglib-location>
		</taglib>
	</jsp-config>
调用标签,完成判断----presenttag.jsp

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="mytag" uri="mldn"%>
<html>
<head><title></title></head>
<body>
	<%
		String scope = "session" ;	// 假设现在判断的是session范围
		session.setAttribute("username","李兴华") ;
	%>
	<mytag:present name="username" scope="<%=scope%>">
		<h2><%=scope%>范围存在属性,内容是:“${sessionScope.username}”</h2>
	</mytag:present>
	<mytag:present name="allusers" scope="request">
		<h2>request范围存在属性,内容是:“${requestScope.allusers}”</h2>
	</mytag:present>
</body>
</html>

开发迭代标签

开发迭代标签处理类----IterateTag.java

package org.tagdemo ;
import java.util.* ;
import javax.servlet.jsp.* ;
import javax.servlet.jsp.tagext.* ;

public class IterateTag extends TagSupport {
	private String name ;
	private String scope ;
	private String id ;	// 这个id用于保存集合中的每一个元素
	private Iterator<?> iter = null ;
	public int doStartTag()
               throws JspException{
		Object value = null ;
		if("page".equals(this.scope)){
			value = super.pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE) ;
		}
		if("request".equals(this.scope)){
			value = super.pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE) ;
		}
		if("session".equals(this.scope)){
			value = super.pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE) ;
		}
		if("application".equals(this.scope)){
			value = super.pageContext.getAttribute(this.name,PageContext.APPLICATION_SCOPE) ;
		}
		if(value!=null && value instanceof List<?>){
			this.iter = ((List<?>)value).iterator() ;
			if(iter.hasNext()){
				// 将属性保存在page属性范围之中
				super.pageContext.setAttribute(this.id,iter.next()) ;
				return TagSupport.EVAL_BODY_INCLUDE ;
			} else {
				return TagSupport.SKIP_BODY ;
			}
		} else {
			return TagSupport.SKIP_BODY ;
		}
	}

	public int doAfterBody()
                throws JspException{
		if(iter.hasNext()){
			// 将属性保存在page属性范围之中
			super.pageContext.setAttribute(this.id,iter.next()) ;
			return TagSupport.EVAL_BODY_AGAIN ;	// 反复执行doAfterBody()方法
		} else {
			return TagSupport.SKIP_BODY ;
		}
	}

	public void setName(String name){
		this.name = name ;
	}
	public void setScope(String scope){
		this.scope = scope ;
	}
	public void setId(String id){
		this.id = id ;
	}
	public String getName(){
		return this.name ;
	}
	public String getScope(){
		return this.scope ;
	}
	public String getId(){
		return this.id ;
	}
}
修改标签描述文件,增加迭代标签配置----mldntag.tld

<tag>
	<name>present</name>
	<tag-class>org.lxh.tagdemo.AttributeTag</tag-class>
	<body-content>JSP</body-content>
	<attribute>
		<name>name</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
	<attribute>
		<name>scope</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
    </tag>
    <tag>
	<name>iterate</name>
	<tag-class>org.lxh.tagdemo.IterateTag</tag-class>
	<body-content>JSP</body-content>
	<attribute>
		<name>name</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
	<attribute>
		<name>scope</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
	<attribute>
		<name>id</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
    </tag>
编写JSP执行标签---iteratetag.jsp

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.util.*"%>
<%@ taglib prefix="mytag" uri="mldn"%>
<html>
<head><title></title></head>
<body>
<%	// 此代码只是为了测试,实际中此部分应该由servlet传递
	List<String> all = new ArrayList<String>() ;
	all.add("www.baidu.cn") ;
	all.add("www.google.cn") ;
	all.add("www.CSDN.com") ;
	request.setAttribute("all",all) ;	// 将内容保存在标签执行
%>
<mytag:present name="all" scope="request">
	<mytag:iterate id="url" name="all" scope="request">
		<h3>网站:${url}</h3>
	</mytag:iterate>
</mytag:present>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------

简单标签实现迭代

定义迭代标签处理类----SimpleIterateTag.java

package org.lxh.tagdemo ;
import java.io.* ;
import java.util.* ;
import java.text.* ;
import javax.servlet.jsp.* ;
import javax.servlet.jsp.tagext.* ;
public class SimpleIterateTag extends SimpleTagSupport {
	private String id ;
	private String name ;
	private String scope ;
	public void doTag()
           throws JspException,
                  IOException{
		Object value = null ;
		if("page".equals(this.scope)){
			value = super.getJspContext().getAttribute(this.name,PageContext.PAGE_SCOPE) ;
		}
		if("request".equals(this.scope)){
			value = super.getJspContext().getAttribute(this.name,PageContext.REQUEST_SCOPE) ;
		}
		if("session".equals(this.scope)){
			value = super.getJspContext().getAttribute(this.name,PageContext.SESSION_SCOPE) ;
		}
		if("application".equals(this.scope)){
			value = super.getJspContext().getAttribute(this.name,PageContext.APPLICATION_SCOPE) ;
		}
		if(value != null && value instanceof List<?>){
			Iterator<?> iter = ((List<?>) value).iterator() ;
			while(iter.hasNext()){
				super.getJspContext().setAttribute(id,iter.next()) ;
				super.getJspBody().invoke(null) ;
			}
		}
	}
	public void setId(String id){
		this.id = id ;
	}
	public void setName(String name){
		this.name = name ;
	}
	public void setScope(String scope){
		this.scope = scope ;
	}
	public String getId(){
		return this.id ;
	}
	public String getName(){
		return this.name ;
	}
	public String getScope(){
		return this.scope ;
	}
}
修改标签描述文件,增加新的标签配置----mldntag.tld

<tag>
	<name>simpleiterate</name>
	<tag-class>org.lxh.tagdemo.SimpleIterateTag</tag-class>
	<body-content>scriptless</body-content>
	<attribute>
		<name>name</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
	<attribute>
		<name>scope</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
	<attribute>
		<name>id</name>
		<required>true</required>
		<rtexprvalue>true</rtexprvalue>
	</attribute>
    </tag>
在JSP中使用标签----simpleiteratetag.jsp

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.util.*"%>
<%@ taglib prefix="mytag" uri="mldn"%>
<html>
<head><title></title></head>
<body>
	<%
		List<String> all = new ArrayList<String>() ;
<pre code_snippet_id="415000" snippet_file_name="blog_20140703_7_3493509" name="code" class="java">	        all.add("www.baidu.cn") ;
	        all.add("www.google.cn") ;
	        all.add("www.CSDN.com") ;
request.setAttribute("all",all) ;%><h1><mytag:simpleiterate id="url" name="all" scope="request"><h2>网站:${url}</h2></mytag:simpleiterate></h1></body></html>
 










  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园信息化系统解决方案旨在通过先进的信息技术,实现教育的全方位创新和优质资源的普及共享。该方案依据国家和地方政策背景,如教育部《教育信息化“十三五”规划》和《教育信息化十年发展规划》,以信息技术的革命性影响为指导,推进教育信息化建设,实现教育思想和方法的创新。 技术发展为智慧校园建设提供了强有力的支撑。方案涵盖了互连互通、优质资源共享、宽带网络、移动APP、电子书包、电子教学白板、3D打印、VR虚拟教学等技术应用,以及大数据和云计算技术,提升了教学数据记录和分析水平。此外,教育资源公共服务平台、教育管理公共服务平台等平台建设,进一步提高了教学、管控的效率。 智慧校园系统由智慧教学、智慧管控和智慧办公三大部分组成,各自具有丰富的应用场景。智慧教学包括微课、公开课、精品课等教学资源的整合和共享,支持在线编辑、录播资源、教学分析等功能。智慧管控则通过平安校园、可视对讲、紧急求助、视频监控等手段,保障校园安全。智慧办公则利用远程视讯、无纸化会议、数字会议等技术,提高行政效率和会议质量。 教育录播系统作为智慧校园的重要组成部分,提供了一套满足学校和教育局需求的解决方案。它包括标准课室、微格课室、精品课室等,通过自动五机位方案、高保真音频采集、一键式录课等功能,实现了优质教学资源的录制和共享。此外,录播系统还包括互动教学、录播班班通、教育中控、校园广播等应用,促进了教育资源的均衡化发展。 智慧办公的另一重点是无纸化会议和数字会议系统的建设,它们通过高效的文件管理、会议文件保密处理、本地会议的音频传输和摄像跟踪等功能,实现了会议的高效化和集中管控。这些系统不仅提高了会议的效率和质量,还通过一键管控、无线管控等设计,简化了操作流程,使得会议更加便捷和环保。 总之,智慧校园信息化系统解决方案通过整合先进的信息技术和教学资源,不仅提升了教育质量和管理效率,还为实现教育均衡化和资源共享提供了有力支持,推动了教育现代化的进程。
智慧校园信息化系统解决方案旨在通过先进的信息技术,实现教育的全方位创新和优质资源的普及共享。该方案依据国家和地方政策背景,如教育部《教育信息化“十三五”规划》和《教育信息化十年发展规划》,以信息技术的革命性影响为指导,推进教育信息化建设,实现教育思想和方法的创新。 技术发展为智慧校园建设提供了强有力的支撑。方案涵盖了互连互通、优质资源共享、宽带网络、移动APP、电子书包、电子教学白板、3D打印、VR虚拟教学等技术应用,以及大数据和云计算技术,提升了教学数据记录和分析水平。此外,教育资源公共服务平台、教育管理公共服务平台等平台建设,进一步提高了教学、管控的效率。 智慧校园系统由智慧教学、智慧管控和智慧办公三大部分组成,各自具有丰富的应用场景。智慧教学包括微课、公开课、精品课等教学资源的整合和共享,支持在线编辑、录播资源、教学分析等功能。智慧管控则通过平安校园、可视对讲、紧急求助、视频监控等手段,保障校园安全。智慧办公则利用远程视讯、无纸化会议、数字会议等技术,提高行政效率和会议质量。 教育录播系统作为智慧校园的重要组成部分,提供了一套满足学校和教育局需求的解决方案。它包括标准课室、微格课室、精品课室等,通过自动五机位方案、高保真音频采集、一键式录课等功能,实现了优质教学资源的录制和共享。此外,录播系统还包括互动教学、录播班班通、教育中控、校园广播等应用,促进了教育资源的均衡化发展。 智慧办公的另一重点是无纸化会议和数字会议系统的建设,它们通过高效的文件管理、会议文件保密处理、本地会议的音频传输和摄像跟踪等功能,实现了会议的高效化和集中管控。这些系统不仅提高了会议的效率和质量,还通过一键管控、无线管控等设计,简化了操作流程,使得会议更加便捷和环保。 总之,智慧校园信息化系统解决方案通过整合先进的信息技术和教学资源,不仅提升了教育质量和管理效率,还为实现教育均衡化和资源共享提供了有力支持,推动了教育现代化的进程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值