2 Replies Latest reply on Nov 21, 2003 1:39 PM by Joe Fraser

    JSP Tag Library Runtime Problem

    Joe Fraser Newbie

      I have done every thing by the book. I know because I have tried every thing. I know I am doing alot right, because the jsp that uses the tag library, actually compiles. but the following source code will not run.
      help anybody.

      package org.apache.jsp;

      import javax.servlet.jsp.*;
      import javax.servlet.jsp.tagext.*;

      import java.io.*;
      import java.util.*;

      /**
      *
      * @version 1.0, 05/02/00
      * @author Joe Fraser
      * Copyright:
      * Copyright (c) 2000 Marketing.Comm. All Rights Reserved.
      * File Name:
      * ReportServlet.java
      * Purpose:
      * This Servlet is an example that gets a connection from a SQL Server pool, and
      * then queries a table which is written to output as html. The Servlet reads initalization parameters from
      * the file servlet.properties. The connection pool reads the file db.properties.
      * Output:
      * The output is an html page.
      * Note:
      * This servlet was tested with servletrunner using the -s and -d options.
      * History:
      * 1.0, 05/02/00 - Joe Fraser
      *
      */

      public class AppletPluginTag
      extends BodyTagSupport
      {
      private PageContext jspPageContext;
      private String name;
      private String width;
      private String height;
      private String code;
      private String codeBase;
      private String archive;
      private String [] searchList = {"\"CODE\"", "\"CODEBASE\"", "\"ARCHIVE\""};

      public AppletPluginTag()
      {
      init();
      }

      protected void init()
      {
      name = null;
      width = null;
      height = null;
      code = null;
      codeBase = null;
      archive = null;
      jspPageContext = null;
      }

      public void setPageContext(PageContext aPageContext)
      {
      jspPageContext = aPageContext;
      return;
      }
      // this next three set methods are automatically called during
      // the tag processing because they are attributes of the tag
      public void setName(String aName)
      {
      name = aName;
      }

      public void setWidth(String aWidth)
      {
      width = aWidth;
      }

      public void setHeight(String aHeight)
      {
      height = aHeight;
      }

      public String getName()
      {
      return(name);
      }

      public String getWidth()
      {
      return(width);
      }

      public String getHeight()
      {
      return(height);
      }

      protected void finishTopOfObjectTag(StringBuffer outBuffer)
      {
      outBuffer.append(width);
      outBuffer.append(" HEIGHT = ");
      outBuffer.append(height);
      outBuffer.append(" NAME = \"");
      outBuffer.append(name);
      outBuffer.append("\"\n\t"); // end line one

      outBuffer.append("codebase=\"http://java.sun.com/products/plugin/autodl/jinstall-1_4_0-win.cab#Version=1,4,0,0\">");
      outBuffer.append("\n"); // end line two

      }

      protected void finishRestOfObjectTag(StringBuffer outBuffer)
      {
      outBuffer.append("\n"); // end line
      outBuffer.append("<PARAM NAME=\"scriptable\" VALUE=\"true\">");
      outBuffer.append("\n"); // end line
      outBuffer.append("");
      outBuffer.append("\n"); // end line
      outBuffer.append ("<EMBED type=\"application/x-java-applet;jpi-version=1.4\" CODE = ");
      outBuffer.append(code);
      outBuffer.append(" CODEBASE = ");
      outBuffer.append(codeBase);
      outBuffer.append(" ARCHIVE = ");
      outBuffer.append(archive);
      outBuffer.append(" NAME = \"");
      outBuffer.append(name);
      outBuffer.append("\"\n"); // end line
      outBuffer.append("WIDTH = ");
      outBuffer.append(width);
      outBuffer.append(" HEIGHT = ");
      outBuffer.append(height);
      outBuffer.append(" scriptable=true");
      outBuffer.append("\n"); // end line
      outBuffer.append("pluginspage=\"http://java.sun.com/products/plugin/index.html#download\">");
      outBuffer.append("\n");
      outBuffer.append("");
      outBuffer.append("\n");
      outBuffer.append("NO JDK 1.4 support for Applet!!");
      outBuffer.append("\n");
      outBuffer.append("");
      outBuffer.append("\n");
      outBuffer.append("");
      outBuffer.append("\n");
      outBuffer.append("");
      outBuffer.append("\n");
      outBuffer.append("");
      outBuffer.append("\n");

      }

      public int doStartTag()
      throws JspException
      {
      // pageContext is a given object set before this method
      StringBuffer outBuf;
      outBuf = new StringBuffer("<OBJECT classid=\"clsid:CAFEEFAC-0014-0000-0000-ABCDEFFEDCBA\" WIDTH = ");
      finishTopOfObjectTag(outBuf);
      try {
      JspWriter writer = jspPageContext.getOut();
      writer.print(outBuf.toString());
      // writer.print("out doStartTag()");
      }
      catch (IOException e)
      {
      throw new JspException(e.getMessage() + ": error in doStartTag()");
      }
      return(EVAL_BODY_BUFFERED);
      }

      public int doAfterBody() // After the body is already written
      throws JspException
      {
      String tag = null;
      ArrayList bodyTagList = new ArrayList();
      // bodyContent is a given object
      String bodyText = bodyContent.getString();

      // start parsing the text
      StringTokenizer bodyTokens = new StringTokenizer(bodyText, "\n");
      while(bodyTokens.hasMoreTokens())
      {
      bodyTagList.add(bodyTokens.nextToken());
      }

      // now that I have an array of PARAM Tags find the CODE, CODEBASE, and ARCHIVE
      for (int i = 0; i < bodyTagList.size(); i++)
      {
      tag = (String)bodyTagList.get(i);
      if (tag.trim().length() > 0)
      {
      // find NAME=
      int beforeNameIndex = tag.indexOf("NAME=", 0);
      int beforeValueIndex = tag.indexOf("VALUE=", beforeNameIndex + 5);
      String nameIs = tag.substring(beforeNameIndex + 5, beforeValueIndex);
      // find VALUE
      int beforeTagEnd = tag.indexOf(">", beforeValueIndex + 6);
      String valueIs = tag.substring(beforeValueIndex + 6, beforeTagEnd);
      boolean found = false;
      int subscript = -1;
      for (int j = 0; j < searchList.length; j++)
      {
      if (nameIs.equalsIgnoreCase(searchList))
      {
      found = true;
      subscript = j;
      break;
      }
      }
      if (found)
      {
      if (subscript == 0)
      code = new String(valueIs);
      else if (subscript == 1)
      codeBase = new String(valueIs);
      else if (subscript == 2)
      archive = new String(valueIs);
      }
      }
      }

      return (SKIP_BODY); // single iteration return
      }

      public int doEndTag()
      throws JspException
      {

      // pageContext is a given object
      StringBuffer outBuf = null;
      JspWriter writer = jspPageContext.getOut();
      outBuf = new StringBuffer("<PARAM NAME=\"TYPE\" VALUE=\"application/x-java-applet;jpi-version=1.4\">");
      finishRestOfObjectTag(outBuf);
      try {
      writer.print(outBuf.toString());
      }
      catch (IOException e)
      {
      throw new JspException(e.getMessage() + ": error in doEndTag()");
      }
      return(EVAL_PAGE);
      }

      public void release()
      {
      super.release();
      init();
      }

      }

        • 1. Re: JSP Tag Library Runtime Problem(me again)
          Joe Fraser Newbie

          I am attaching the War file, so if you are brave you can help me. It is very small, just a proof of concept thing.

          JOE

          • 2. Re: JSP Tag Library Runtime Problem
            Joe Fraser Newbie

            Yes, I solved my own problem, here are the steps,
            the first four are not required.

            1) installed jboss-3.2.3RC1
            2) changed to tomcat50.sar(not tomcat41.sar)
            3) uncommented out the invoker servlet in web.xml
            file of tomcat50.sar (don't know why they do that)
            4) changed my classpath to include jsp-api.jar and servlet-api.jar (if you don't do this java.servlet.jar) will be used and this is old)
            5) stopped using org.apache.jsp as a package for my
            tag library. I now use myTagLib, I started that because the generated jsp file was importing that, but it is a mistake to use org.apache.jsp. Of course, I doubt that other people will make this mistake, but who knows