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类, ...
随机推荐
- Which Python memory profiler is recommended
http://stackoverflow.com/questions/110259/which-Python-memory-profiler-is-recommended/110826#110826
- 加州wonders教材扫盲
加州语文教材主要包含以下内容: 1.主教材Reading/Writing Workshop(读写研讨) 2.拓展教材Literature Anthology(文学选集) 3.延伸阅读材料Leveled ...
- 使用pycharm远程调试python代码
使用 pycharm 进行 python 代码远程调试 pycharm 的远程调试是从远程机器连接到本地机器,需要在远程机器的py文件中指定本地机器的IP和端口. 远程机器上,通过easy_insta ...
- android自动填写短信验证码
广播类 package com.examp.azuoyoutong.listner; import java.util.regex.Matcher;import java.util.regex.Pat ...
- [转载]CAD文件版本
http://blog.sina.com.cn/s/blog_4c9fa4dd0101il1v.html 在工作中会遇到打开一张图纸时出现“图形文件无效”的提示,大部都是因为用低版本软件打开了高版本的 ...
- python故障查找:超时未设置
最近一台基于python的应用服务总是出现问题.需求是用户可以在页面上提交批量处理任务,后台把这些任务入到一个Queue里排队处理,然后通过一个线程专门处理.现在总是偶尔出现假死状态,任务处理中断执行 ...
- 解决: Fail to create empty document
做 Programming Windows with MFC 2nd 的例子 MyWord 的时候. 发现启动的时候总是报错: Fail to create empty document. 搜索了一下 ...
- protocol(协议)的一些要点
//遵循协议的变量声明 //要求你创建的PErson对象必须是遵循了 PersonProtocol Person<PersonProtocol> * p2 = [[Person alloc ...
- runcluvfy.sh运行结果
$ ./runcluvfy.sh stage -pre crsinst -n rac11g1,rac11g2 -verbose Performing pre-checks for cluster se ...
- css 字体样式
[强制] font-family 属性中的字体族名称应使用字体的英文 Family Name,其中如有空格,须放置在引号中. 解释: 所谓英文 Family Name,为字体文件的一个元数据,常见名称 ...