javaWeb 使用jsp开发 if else 标签
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 标签的更多相关文章
- javaWeb 使用jsp开发 html过滤标签
1.jsp调用代码 <t:htmlFilter> <a href="${pageContext.request.contextPath }/index.jsp"& ...
- javaWeb 使用jsp开发 foreach 标签
1.jsp代码 测试数据 <% List<String> list = new ArrayList<String>(); list.add("aaa" ...
- javaWeb 使用jsp开发 if 标签
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- javaWeb 在jsp中 使用自定义标签输出访问者IP
1.java类,使用简单标签,jsp2.0规范, 继承 SimpleTagSupport public class ViewIpSimpleTag extends SimpleTagSupport { ...
- 深入分析JavaWeb Item23 -- jsp自己定义标签开发入门
一.自己定义标签的作用 自己定义标签主要用于移除Jsp页面中的java代码. 二.自己定义标签开发和使用 2.1.自己定义标签开发步骤 1.编写一个实现Tag接口的Java类(标签处理器类) 要编写一 ...
- JavaWeb之 JSP:自定义标签
当jsp的内置标签和jstl标签库内的标签都满足不了需求,这时候就需要开发者自定义标签. 自定义标签 下面我们先来开发一个自定义标签,然后再说它的原理吧! 自定义标签的开发步骤 步骤一 编写一个普通的 ...
- JavaWeb之 JSP:内置对象,EL表达式,JSP标签基础
JSP的内置对象 什么是JSP的内置对象呢? 在JSP页面进行编程的时候,如果我们要使用一些对象,如:HttpSession,ServletConfig,ServletContext这些对象,如果每次 ...
- JSP内置标签 JSP中JavaBean标签 JSP开发模式 EL和JSTL快速入门
2 JSP内置标签(美化+业务逻辑) 1)为了取代<%%>脚本形式,使用JSP标签/JSP动作,目的:与JSP页面的美化,即JSP面页都是由标签组成,不再有其它的内容 2)JSP内 ...
- JavaWeb之 JSP:自定义标签的创建和使用
当jsp的内置标签和jstl标签库内的标签都满足不了需求,这时候就需要开发者自定义标签. 下面我们先来开发一个自定义标签,然后再说它的原理吧! 自定义标签的开发步骤 步骤一 编写一个普通的java类, ...
随机推荐
- iOS:iOS开发非常全的三方库、插件等等
iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...
- A股回归牛市?
A股回归牛市? 国际知名投行摩根士丹利(Morgan Stanley)预计,中国股市将恢复牛市大涨行情. 该行预计上证综指明年底将报4,400点,较目前的3,241点水平涨36%.预计每股盈余(EPS ...
- winston日志管理2
上次讲到 Exceptions 例外 Handling Uncaught Exceptions with winston 使用winston处理未捕获的异常(这个如果对于异步,我不是很喜欢用) 使用 ...
- MongoDB安装、管理工具、操作
1. mongoDB安装.启动.关闭 1.1 下载安装包 wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.3.tgz 1.2 ...
- HBase shell
进入命令行 ./hbase shell 查看HBase shell帮助 help 查看命令帮助 直接输入命令回撤 创建命名空间 create_namespace 'ns1' 查看命名空间 list_n ...
- Feature Scaling
定义:Feature scaling is a method used to standardize the range of independent variables or features of ...
- JQuery Delay Hover效果
CSS代码 .tbui_aside_float_bar { position: fixed; left: 50%; bottom: 120px; margin-left: 608px; border- ...
- Leetcode: Rotate Function
Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotati ...
- 免费VPN 实测可用
vpngate.net 的镜像站点列表 (更新于 2014-05-18 03:06:00 UTC): http://121.135.220.121:26633/cn/ (Mirror location ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...