<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      JSP中的TagLib應用(4-1)

      [摘要]下面到了關鍵部分樂。 對tag進行處理。其實很多情況下我們是使用已經提供的taglib.別人/公司已經做好了tag和處理部分,打好了包 我們需要做的只是在我們的jsp中去應用.但是當我們自己做個taglib時, 就需要編寫這部分tag handler了. 這里只針對上面文件里提到的insert t...
      下面到了關鍵部分樂。 對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中定義了一些接口.




      日韩精品一区二区三区高清