做标签处理类的时候 老是出错  说类找不到 我是新手请指点 如果哪为大哥给一个简单的标签处理的源代码最好了 ,是不是jsp自定义标签必须得有struts结构 要不怎么老提示找不到啊 请各位帮忙了package mytag;    
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.sql.*;
import java.math.*;
import java.util.*;
 
public class HelloWorldTag extends TagSupport {     
  public HelloWorldTag() {
  }
  public int doStartTag() throws JspTagException{
    return EVAL_BODY_INCLUDE;
  }
  public int doEndTag() throws JspTagException{
    try {
      pageContext.getOut().write("Hello World");
    }
    catch (IOException ex) {
      
    }
    return EVAL_PAGE;
  }
}

解决方案 »

  1.   

    这是刚用过的一个会话验证的客户化标签,绝对能用,不忽悠你:)
    ValidateSessionTag.java
    package com.ecode.util;import java.io.IOException;
    import javax.servlet.http.HttpSession;
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspWriter;
    import javax.servlet.jsp.PageContext;
    import javax.servlet.jsp.tagext.TagSupport;
    import com.ecode.util.Constants;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;/**
     * <strong>ValidateSessionTag</strong> is a custom tag used
     * with this application to determine is a user has a current
     * validate session.
     */public final class ValidateSessionTag extends TagSupport {
        private String name = Constants.USER_KEY;
        private String page = Constants.A_LOGON_JSP;
        private Log log =LogFactory.getLog(this.getClass().getName());    public int doEndTag() throws JspException {
    boolean valid = false;
    HttpSession session = pageContext.getSession();
    if ((session != null) && (session.getAttribute(name) == "accounts"))
        valid = true; if (valid)
        return (EVAL_PAGE);
    else {
        try {
    pageContext.forward(page);
        } catch (Exception e) {
    throw new JspException(e.toString());
        }
        return (SKIP_PAGE);
    }
        }
        public int doStartTag() throws JspException {
    return (SKIP_BODY);
        }
        public String getName() {
    return (this.name);
        }
        public String getPage() {
    return (this.page);
        }
        public void release() {
            super.release();
            this.name = Constants.USER_KEY;
            this.page = Constants.A_LOGON_JSP;
        }
        public void setName(String name) {
    this.name = name;
        }
        public void setPage(String page) {
    this.page = page;
        }
    }app.tld<?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib
      PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
      "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <taglib>
      <tlibversion>1.0</tlibversion>
      <jspversion>1.1</jspversion>
      <shortname>Application Tag Library</shortname>
      <uri>http://jakarta.apache.org/taglibs/struts-example-1.0</uri>
      <info>
        This tag library contains functionality for the Addressbook Struts
        Sample Application. With small modifications, they can be used
        as generic tags.
      </info>  <tag>
        <name>validateSession</name>
        <tagclass>com.ecode.util.ValidateSessionTag</tagclass>
        <bodycontent>empty</bodycontent>
        <info>
          Validate that there is a currently logged on user, by checking for
          the existence of a session-scope bean under the specified name.
          If there is no such bean, forward control to the specified page,
          which will typically be a logon form.      Attributes:
          name - Name of the session-scope bean to check for
          page - Context-relative path to the logon page
        </info>
        <attribute>
          <name>name</name>
          <required>false</required>
          <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
          <name>page</name>
          <required>false</required>
          <rtexprvalue>true</rtexprvalue>
        </attribute>
      </tag>
      </taglib>Constants.java
    package com.ecode.util;/**
     * <strong>Constants</strong> holds all of the global constants used throughout
     * the AddressBook application
     */
    public final class Constants {
    // Session keys
        public static final String DATABASE_KEY = "database";
        public static final String USER_KEY = "user";
        
        public static final String SQLSTMT_KEY = "sqlstatement";    
        //Forward values
        public static final String FORWARD_SUCCESS = "success";
        public static final String FORWARD_FAILURE = "failure";
        public static final String FORWARD_ERROR = "error";
        public static final String FORWARD_CONFIRMATION = "confirmation";
        public static final String FORWARD_INSERT = "insert";   
        // JSP files references in this application
        public static final String DISPLAY_JSP = "/display.jsp";
        public static final String INDEX_JSP = "/index.jsp";
        public static final String LOGOFF_JSP = "/logoff.jsp";
        public static final String A_LOGON_JSP = "/view/index.jsp";
        public static final String AU_LOGON_JSP = "/view/adminUser/login.jsp";
        public static final String OU_LOGON_JSP = "/view/oceanUser/login.jsp";
        public static final String MAINMENU_JSP = "/mainMenu.jsp";
        public static final String SEARCH_JSP = "/search.jsp";
        
        // Database table name used for this sample
        public static final String TABLENAME = "ADDRESSBOOK_TABLE";}
    web.xml中添加<taglib>
        <taglib-uri>/WEB-INF/app.tld</taglib-uri>
        <taglib-location>/WEB-INF/app.tld</taglib-location>
    </taglib>
    使用的时候在jsp里加入<app:validateSession/>
      

  2.   

    自定义标签和struts没关系~
    应该是你编译路径和运行路径的问题~(通常找不到包或类就是这样原因)
      

  3.   

    找不到可能是由于你标签的TLD文档写了吗?
    WEB。XML文件中指定了标签库吗?
      

  4.   

    xuyang821225 老哥把你的qq号告诉我吧
      

  5.   

    自定义标签和struts没关系
    我觉得也是你没有在WEB.XML中指定你的标签自定义标签的大步骤如下:
    1〉extends SimpleTagSupprot 编写自己的标签类
    2〉编写*.tld文件
    3〉在web.xml中发布
    4〉在页面中使用你的自定义标签
    大概就是这样的 具体的东西还得你自己看看书
      

  6.   

    我知道过程但是标签类一编译就出错 我现在正在找错呵呵 郁闷ing