下面到了关键部分乐。 对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中定义了一些接口.
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器