1.jsp页面调用代码

<t:choose>
<t:when test="${user==null }">还没有登录</t:when>
<t:otherwise>欢迎您: ${user }</t:otherwise>
</t:choose>

2.tld文件代码

    <tag>
<name>choose</name>
<tag-class>de.bvb.web.tag.ChooseTag</tag-class>
<body-content>scriptless</body-content>
</tag>
<tag>
<name>when</name>
<tag-class>de.bvb.web.tag.WhenTag</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>test</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>otherwise</name>
<tag-class>de.bvb.web.tag.OtherWiseTag</tag-class>
<body-content>scriptless</body-content>
</tag>

3.标签实现类代码

3.1 父标签代码

package de.bvb.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport; public class ChooseTag extends SimpleTagSupport {
private boolean executed; public boolean isExecuted() {
return executed;
} public void setExecuted(boolean executed) {
this.executed = executed;
} @Override
public void doTag() throws JspException, IOException {
this.getJspBody().invoke(null);
}
}

3.2 if 标签代码

package de.bvb.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport; public class WhenTag extends SimpleTagSupport {
private boolean test; public void setTest(boolean test) {
this.test = test;
} @Override
public void doTag() throws JspException, IOException {
ChooseTag parent = (ChooseTag) this.getParent();
if (!parent.isExecuted() && test) {
this.getJspBody().invoke(null);
parent.setExecuted(true);
} } }

3.3 else 标签代码

package de.bvb.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport; public class OtherWiseTag extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
ChooseTag parent = (ChooseTag) this.getParent();
if (!parent.isExecuted()) {
this.getJspBody().invoke(null);
parent.setExecuted(true);
}
} }

javaWeb 使用jsp开发 if else 标签的更多相关文章

  1. javaWeb 使用jsp开发 html过滤标签

    1.jsp调用代码 <t:htmlFilter> <a href="${pageContext.request.contextPath }/index.jsp"& ...

  2. javaWeb 使用jsp开发 foreach 标签

    1.jsp代码 测试数据 <% List<String> list = new ArrayList<String>(); list.add("aaa" ...

  3. javaWeb 使用jsp开发 if 标签

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  4. javaWeb 在jsp中 使用自定义标签输出访问者IP

    1.java类,使用简单标签,jsp2.0规范, 继承 SimpleTagSupport public class ViewIpSimpleTag extends SimpleTagSupport { ...

  5. 深入分析JavaWeb Item23 -- jsp自己定义标签开发入门

    一.自己定义标签的作用 自己定义标签主要用于移除Jsp页面中的java代码. 二.自己定义标签开发和使用 2.1.自己定义标签开发步骤 1.编写一个实现Tag接口的Java类(标签处理器类) 要编写一 ...

  6. JavaWeb之 JSP:自定义标签

    当jsp的内置标签和jstl标签库内的标签都满足不了需求,这时候就需要开发者自定义标签. 自定义标签 下面我们先来开发一个自定义标签,然后再说它的原理吧! 自定义标签的开发步骤 步骤一 编写一个普通的 ...

  7. JavaWeb之 JSP:内置对象,EL表达式,JSP标签基础

    JSP的内置对象 什么是JSP的内置对象呢? 在JSP页面进行编程的时候,如果我们要使用一些对象,如:HttpSession,ServletConfig,ServletContext这些对象,如果每次 ...

  8. JSP内置标签 JSP中JavaBean标签 JSP开发模式 EL和JSTL快速入门

    2 JSP内置标签(美化+业务逻辑)   1)为了取代<%%>脚本形式,使用JSP标签/JSP动作,目的:与JSP页面的美化,即JSP面页都是由标签组成,不再有其它的内容   2)JSP内 ...

  9. JavaWeb之 JSP:自定义标签的创建和使用

    当jsp的内置标签和jstl标签库内的标签都满足不了需求,这时候就需要开发者自定义标签. 下面我们先来开发一个自定义标签,然后再说它的原理吧! 自定义标签的开发步骤 步骤一 编写一个普通的java类, ...

随机推荐

  1. Java工具类(获取当前主机操作系统名)

    package com.fly.jenkins.util; /** * 操作系统类: 获取System.getProperty("os.name")对应的操作系统 * * @aut ...

  2. SoapUI接口测试·第一个HTTP Request接口请求和断言

    一.新建SOAP项目 [File]-[New SOAP Project],在[Project Name]输入{工程名},点击[OK].   二.新建TestSuite 选中项目,右键选择[New Te ...

  3. php 配置本地自定义域名

    一.设置host文件 二.设置httpd.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf 三.设置httpd-vhosts.conf ...

  4. shell eval用法

    转自:http://blog.csdn.net/w_ww_w/article/details/7075867 eval可读取一连串的参数,然后再依参数本身的特性来执行.eval是shell内建命令,可 ...

  5. python 之 append extend

    概述 append和extend针对python的列表 列表内的元素为对象,可以为数字.字符串.列表等等 append添加的是一个对象 extend添加一个列表 例子 append >>& ...

  6. Visual Studio Debugger AutoExp.dat & Visualization Framework

    bing.com搜索: autoexp.dat 参考资料: AutoExp.dat http://www.virtualdub.org/blog/pivot/entry.php?id=120 http ...

  7. iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)

    在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...

  8. 学习jsp(1)

    我的开发环境是:jdk1.7;netbean ;tomcat7. 尝试着写了第一个程序: ublic class myServlet extends HttpServlet{    @Override ...

  9. Lintcode: Interval Sum II

    Given an integer array in the construct method, implement two methods query(start, end) and modify(i ...

  10. Android--HTTP协议

    1 package com.http.get; 2 3 import java.io.FileOutputStream; 4 import java.io.IOException; 5 import ...