- 浏览: 518856 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (294)
- Java基础 (40)
- 架构分析 (37)
- 开发心得 (22)
- 架构乐园 (12)
- Java Web (6)
- 大牛专区 (5)
- 转载专区 (40)
- 小技巧 (16)
- Linux专区 (8)
- linux (3)
- Spring (2)
- N (1)
- 前台JS (1)
- SAP NETWEAVER (3)
- JMS (4)
- queue (1)
- 数据模型 (2)
- oracle (2)
- sqlserver (2)
- ubuntu (2)
- install gcc (1)
- MEMCACHED (2)
- SQLSERVER 驱动 (1)
- JVM GC 调优 (1)
- 服务器运维 (1)
- activiti 国际化 中文 (1)
- activiti (1)
- 前端开发 (1)
- tar.gz (1)
- Web安全 (1)
- CSRF (1)
- 技术架构 (4)
- 性能指标 (1)
- 响应时间 (1)
- 淘宝 (1)
- linux安装 (1)
- lucene (1)
- Mongodb (1)
- gis (1)
- 微信授权 code access_token open_id (1)
- Redis java 获取 (1)
- HTTP 跨域 同源策略 cookie (1)
- java 加密 3DES (1)
- CROS (1)
- Cookie (1)
- Rest (1)
- 跨域资源共享 (1)
- 3DES (1)
- Effective java读后感 (1)
- nginx (1)
- Tengine 开发 (1)
- HTTP/1.1 废弃 javaWEB (1)
- 支付宝 支付状态 (1)
- maven jdk (1)
- 应用宝统一链接 (1)
- git (2)
- git 代码上传 (1)
- ubuntu 安装 mysql 5.6 (1)
- Linux 命令学习 (3)
- Linux 命令 60 (2)
- linux 命令 (2)
- linux nginx 安装 (1)
- grant revoke (1)
- linxu jdk profile (1)
- git 使用 (1)
- 架构设计 (1)
- 上海居转户 居转户 (1)
- wind (1)
- elastic-job (1)
- Mysql (1)
- 个人站点 (1)
- nginx lua waf 实现 (1)
- github 算法指南 (1)
- go (1)
- MapReduace 大数据 (1)
- 架构PPT (1)
最新评论
-
jingchh:
帅哥, 这个类是哪个包下面的呢? 应该下载哪个jar包,谢谢~ ...
StringUtils工具类的常用方法 -
Nabulio:
StringUtils工具类的常用方法 -
yuanyuan2597:
那请问,按照你的方法进行修改调用。SELECT locatio ...
根据经纬度实现附近搜索Java实现 -
yangguo:
这个经理有病,埋伏打他一顿。
复试 等电话 -
emparadise329:
进一步学习了子类与父类间的关系
Java 子类对象实例化 面试题
标签开发之几大步骤:
1,开发标签类,继承TagSupport类,
package org.lxh.tagdemo; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class HelloTag extends TagSupport{ public int doStartTag()throws JspException{ JspWriter out =super.pageContext.getOut(); try{ out.println("<h1>hello World!!</h1>"); }catch(Exception e){} return TagSupport.SKIP_BODY; } };
注意点 :编译的时候可能报错,请注意 tomcat路径下,jsp-api.jar的路径问题,把此文件夹放到 java环境下,jdk/jre/lib/ext 包下面,
2,定义一个标签的描述文件,标签的描述文件的后缀 "*.tld",而且此文件也符合XML语法规则。
<?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>firsttag</short-name> <!--为标签库在TLD中的描述名称--> <tag> <name>hello</name> <tag-class>org.lxh.tagdemo.HelloTag</tag-class> <body-content>empty</body-content> </tag> </taglib>
3,在JSP文件之中使用此标签。
4,标签组成部分
4.1>.标签处理类: HelloTag.java;
4.2>.标签描述文件:hellotag.tlc
4.3>.JSP页面: 通过<%@ taglib%>定义标签.
4.4>(可选)在web.xml文件中配置映射名称.
********************************************************************************
1,定义有属性的标签
示例:自定义日期格式化操作
package org.lxh.tagdemo; import java.text.*; import java.util.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class DateTag extends TagSupport{ private String format; //设置属性的时候可以通过setter完成 public int doStartTag()throws JspException{ SimpleDateFormat sdf = new SimpleDateFormat(this.format); //表示进行格式化的日期显示操作 try{ super.pageContext.getOut().write(sdf.format(new Date())); }catch (Exception e){ e.printStackTrace(); } return TagSupport.SKIP_BODY; } public void setFormat(String format){ this.format = format; } public String getFormat(){ return this.format; } };
2,编写 *.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>datetag</short-name> <!--为标签库在TLD中的描述名称--> <tag> <name>date</name> <tag-class>org.lxh.tagdemo.DateTag</tag-class> <body-content>empty</body-content> <attribute> <!-- 定义属性 --> <name>format</name> <required>true</required> <rtexprvalue>true</rtexprvalue><!-- 支持表达式输出 --> </attribute> </tag> </taglib>
3,为了方便的使用,直接在web.xml文件之中定义此标签库.
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <jsp-config> <taglib> <taglib-uri>mldn_date</taglib-uri> <taglib-location>/WEB-INF/datetag.tld</taglib-location> </taglib> </jsp-config> </web-app>
************************************************************************************
TagSupport类的简单介绍:
1,
doStartTag
()
|
2,
int
|
doAfterBody
()
Default processing for a body. |
<!-- Generated by javadoc (build 1.6.0_20) on Fri Jun 04 05:41:16 PDT 2010 -->
<noscript></noscript>SKIP_BODY
static final int SKIP_BODY :
表示表前提内容会被忽略,并且将执行权转交给 doEndTag()方法.
<!-- Generated by javadoc (build 1.6.0_20) on Fri Jun 04 05:41:16 PDT 2010 -->
<noscript></noscript>EVAL_BODY_INCLUDE
static final int EVAL_BODY_INCLUDE
表示重复执行标签体的内容,会重复条用doAfterBody()方法,一直循环执行下去,直到doAfterBody()方法返回SKIP_BODY为止。
<!-- Generated by javadoc (build 1.6.0_20) on Fri Jun 04 05:41:16 PDT 2010 -->
<noscript></noscript>doEndTag
int doEndTag () throws JspException
static int
|
SKIP_PAGE
|
表示JSP页面应该立刻停止执行,并将所有的输出立刻回传到浏览器上
static int
|
EVAL_PAGE
|
表示JSP可以正常的运行完毕。
1.1 编写 *.java 文件:
package org.lxh.tagdemo; import java.text.*; import java.util.*; 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)){ //是否是page范围 value = super.pageContext.getAttribute(this.name,PageContext.REQUEST_SCOPE); } if("session".equals(this.scope)){ //是否是page范围 value = super.pageContext.getAttribute(this.name,PageContext.SESSION_SCOPE); } if("application".equals(this.scope)){ //是否是page范围 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; } };
1.2, 编写 *.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.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> </taglib>
1.3,在 WEB-INF/web.xml 文件里面配置标签属性,
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <jsp-config> <taglib> <taglib-uri>mldn_date</taglib-uri> <taglib-location>/WEB-INF/datetag.tld</taglib-location> </taglib> <taglib> <taglib-uri>mldn_page</taglib-uri> <taglib-location>/WEB-INF/mldntag.tld</taglib-location> </taglib> </jsp-config> </web-app>
1.4,开始写页面
<%@ page contentType="text/html" pageEncoding="GBK"%> <%@ taglib prefix="mytag" uri="mldn_page"%> <html> <head> <title>www.MLDNJAVA.cn</title> </head> <body> <h1> <% String scope = "session"; session.setAttribute("username","zhangsan"); %> <mytag:present name="username" scope="<%=scope%>"> <h2><%=scope%>范围存在属性,内容是:"${sessionScope.username}"</h2> </mytag:present> <mytag:present name="allusers" scope="request"> <h2><%=scope%>范围存在属性,内容是:"${requestScope.allusers}"</h2> </mytag:present> </h1> </body> </html>
<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BodyTagSupport : 是TagSupport类的子类,通过集成BodyTagSupport类实现的标签可以直接处理标签体内容的数
BodyTagSupport类的定义如下:
public class BodyTagSupport extends TagSupport implements BodyTag
标签的开发在实际的开发中使用的很少,主要有第三方的提供的一些插件(重点 )
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
JSP 2.0 之后提供了 SimpleTagSupport 类,直接覆写里面的doTag()方法即可完成。
发表评论
-
eclipse 插件式安装 maven
2016-06-02 16:46 573以下为补充内容: 由于Maven项目地址经常变动,以上ma ... -
HTTP 接口设计指南
2016-01-12 15:04 3898# HTTP 接口设计指北 * 文档主要目的是为设计 ... -
IP 查询开放API
2015-10-12 19:57 935今天项目要用到 查询访问网站用户的IP 然后网上查询了 资料还 ... -
mysql 获取全局唯一值
2015-08-27 13:16 892在涉及数据库存储数据的时候,经常会遇到唯一值问题,有的是主键 ... -
freemarker 数字输出中的逗号问题
2015-08-17 11:50 1585分类: Freemarker2012-04-23 1 ... -
redis cli 客户端连接
2015-07-27 15:31 928Last login: Mon Jul 27 15:31:4 ... -
oracle 链接查询 + Mysql
2015-06-25 19:52 403oracle连接加号(+)的使用方法 假设有 a表 ... -
java中Comparator 时间比价 bug
2015-06-05 14:37 835/** * 消息上架时间排序<br> * @ ... -
MySQL 建立索引
2015-05-05 09:16 737索引是一种特殊的数据结构,可以用来快速查询数据库的特定记录, ... -
[DB][MySql]关于取得自增字段的值、及@@IDENTITY 与并发性问题
2015-04-07 12:43 1519对于刚从Oracle转向MySql的人都会为,MySql中没 ... -
POI 合并单元格
2014-12-25 10:01 1102在用poi在EXECL报表设计的时候,遇到单元格合并问题,用 ... -
两个相同结构表 数据的 对复制
2014-12-09 17:43 779insert into TRP_MEMBER_RECOMMEN ... -
文章主要是介绍DB2取得当前时间的正确解析,如果你是DB2取得当前时间的内容解析,如果你是这方面的新手,对DB2取得当前时间的正确解的相关实际应用不是很了解的话
2013-09-26 19:05 716文章主要是介绍DB2取得当前时间的正确解析,如果你是DB2取 ... -
Lucene 3.X 自定义排序
2013-09-18 16:26 1256Lucene 3.X 自定义排序 发表于 2012 年 ... -
DB2时间函数
2013-08-12 20:11 2617DB2时间函数 DB2时间函数简单总结: ... -
linux 新建用户、用户组 以及为新用户分配权限
2013-08-07 19:14 903linux 新建用户、用户组 以及为新用户分配权限 P ... -
Lucene的分页查询
2013-08-06 16:05 808Lucene的分页查询 Posted on 2012- ... -
lucene3.0_IndexSearcher的基础使用及注意事项
2013-08-06 15:05 922lucene3.0_IndexSearcher的基础使用及注 ... -
ibatis db2 insert模板
2013-05-07 20:32 1107iBatis and DB2 INSERT statemen ... -
DB2 -创建用户和组,数据库
2013-05-06 18:05 71821、增加一个操作系统用户 groupadd test--- ...
相关推荐
jsp应用开发详解.part1 因为上传文件大小受限part2请到我的资源下载 作者:作者:刘晓华//张健//周慧贞 译者:作者:刘晓华//张健//周慧贞 出版社:电子工业出版社 本书结合JSP和Servlet的最新规范,从基本的...
jsp应用开发详解.part2 因为上传文件大小受限part1请到我的资源下载 作者:作者:刘晓华//张健//周慧贞 译者:作者:刘晓华//张健//周慧贞 出版社:电子工业出版社 本书结合JSP和Servlet的最新规范,从基本的...
该资源是《JSP基础与案例开发详解》的随书源代码。提供了书中从第一章-第十七章中讲解的开发工具和源代码。 目录如下: 第1章:Jsp开发的基本知识以及一些常用软件的安装和配置。 第2章:网页布局与修饰,为前端开发...
分为两部分 内容推荐 本书以Java为平台,结合应用实例,强调“实用”性,系统、全面地介绍了JSP语言的基础知识及应用方向。...特性》、《JavamB件开发详解》等一系列Java畅销书籍,发布了中国第一套Java学习视频
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
该资源是《JSP基础与案例开发详解》的随书源代码。提供了书中从第一章-第十七章中讲解的开发工具和源代码。 目录如下: 第1章:Jsp开发的基本知识以及一些常用软件的安装和配置。 第2章:网页布局与修饰,为前端开发...
一个详细的JSP开发应用文档,包含表达式、标签操作等相关实例和解说,可谓JSP开发必备资料
jsp自定义标签开发+TLD文件元素详解+实例;从jsp1.1开始就可以在jsp页面中使用自定义标签了,使用自定义标签不但可以实现代码重用,而且可以使jsp代码更简洁。Jsp2.0的标签扩展API中又增加了SimpleTag接口和其实现类...
该资源是《JSP基础与案例开发详解》的随书源代码。提供了书中从第一章-第十七章中讲解的开发工具和源代码。 目录如下: 第1章:Jsp开发的基本知识以及一些常用软件的安装和配置。 第2章:网页布局与修饰,为前端...
资源名称:JSP应用开发详解(第三版)内容简介:本书结合JSP和Servlet的最新规范,从基本的语法和规范入手,以经验为后盾,以实用为目标,以实例为导向,以实践为指导,深入浅出地讲解了JSP开发中的种种问题。...
分为两部分 内容推荐 本书以Java为平台,结合应用实例,强调“实用”性,系统、全面地介绍了JSP语言的基础知识及应用方向。...特性》、《JavamB件开发详解》等一系列Java畅销书籍,发布了中国第一套Java学习视频
该资源是《JSP基础与案例开发详解》的随书源代码。提供了书中从第一章-第十七章中讲解的开发工具和源代码。 目录如下: 第1章:Jsp开发的基本知识以及一些常用软件的安装和配置。 第2章:网页布局与修饰,为前端开发...
书附带光盘源代码,【内容提要】 飞思科技:本书分7篇共25章,包括JSP应用开发基础、JSP核心技术、Servlet技术的应用、数据库技术的使用、标签语言和表达式语言、Web框架的使用、JSP在实际开发中的应用。
读者注意:这套视频语音讲解中引述的《软件开发课堂 - Java Web基础与案例开发详解》,即后来改名为《JSP基础与案例开发详解》一书的原稿,二者是同一本书。 01基础案例 02网页布局和修饰 03JDBC的应用 04Servlet的...
JSTL_标签库详解大全JSTL常用标签汇总java开发jsp开发.pdf
JSTL_标签库详解大全JSTL常用标签汇总java开发jsp开发归类.pdf
以精简的内容介绍了JSP的语法、Servlet技术、JDBC技术、标签库技术、表达式语言、Struts、JavaServerFace、SpringMVC、Hibernate、Ajax等技术;对于JSP开发中常遇到的典型难点,专门设置了专题进行集中讨论。对于...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
以精简的内容介绍了JSP的语法、Servlet技术、JDBC技术、标签库技术、表达式语言、Struts、JavaServerFace、SpringMVC、Hibernate、Ajax等技术;对于JSP开发中常遇到的典型难点,专门设置了专题进行集中讨论。对于...