首页 域名主机 文章教程 汽车频道 酷车图集 博客之家 网址之家 资源下载 在线音乐 本站论坛
  你现在的位置:首页>>文章教程>>网页编程>>JSP教程>>正文
 
JSP中的TagLib应用(4)
 
[2005-5-5] 来源:lovemz.com 作者:极点学网收集整理  爱我梅州商务网 
 

到了关键部分乐。 对tag进行处理。其实很多情况下我们是使用已经提供的taglib.

别人/公司已经做好了tag和处理部分,打好了包 我们需要做的只是在我们的jsp中去应用.

但是当我们自己做个taglib时, 就需要编写这部分tag handler了.

这里只针对上面文件里提到的insert tag,其他的为了避免重复,就不一一说明了

==================== InsertTag.java==============================

/*

* $Id: InsertTag.java,v 1.13 2000/03/04 02:54:57 brydon Exp $

* Copyright 1999 Sun Microsystems, Inc. All rights reserved.

* Copyright 1999 Sun Microsystems, Inc. Tous droits réservés.

*/

package com.sun.estore.taglib;

import javax.servlet.jsp.JspTagException;

import javax.servlet.jsp.tagext.TagSupport;

import com.sun.estore.util.Debug;

/**

* This class is an easy interface to the JSP template or other

* text that needs to be inserted.

* @author Greg Murray

*/

public class InsertTag extends TagSupport {

private boolean directInclude = false;

private String parameter = null;

private String templateName = null;

private Template template = null;

private TemplateParameter templateParam = null;

/**

* default constructor

*/

public InsertTag() {

super();

}

public void setTemplate(String templateName){

this.templateName = templateName;

}

public void setParameter(String parameter){

this.parameter = parameter;

}

public int doStartTag() {

try{

if (templateName != null){

template = (Template)pageContext.getRequest().getAttribute("template");

}

} catch (NullPointerException e){

Debug.println("Error extracting template from session: " + e);

}

if (parameter != null && template != null) templateParam = (TemplateParameter)template.getParam(parameter);

if (templateParam != null) directInclude = templateParam.isDirect();

return SKIP_BODY;

}

public int doEndTag() throws JspTagException {

try{

pageContext.getOut().flush();

} catch (Exception e){

// do nothing

}

try {

if (directInclude && templateParam != null) {

pageContext.getOut().println(templateParam.getValue());

} else if (templateParam != null) {

if (templateParam.getValue() != null) pageContext.getRequest().getRequestDispatcher(templateParam.getValue()).include(pageContext.getRequest(), pageContext.getResponse());

}

} catch (Throwable ex) {

ex.printStackTrace();

}

return EVAL_PAGE;

}

}

可以看到。InsertTag.java继承了javax.servlet.jsp.tagext.TagSupport类. 因为在TagSupport中定义了一些接口.


本新闻共4页,当前在第1页  1  2  3  4  

 
上一篇文章:JSP中的TagLib应用(3)
下一篇文章:关于在bean里面打印html的利弊看法
本文章为原作者版权所有,如有侵犯您的权益请通知我们,我们会在24小时以内删除
最新5篇热点文章
最新5篇推荐文章
相关文章


关于我们 | 广告刊登 | 合作伙伴 | 友情链接 | 意见反馈 | 帮助HELP| 网站地图

版权所有 Copyright © 2002-2005 爱我梅州商务网
粤ICP备05105236号