在eclipse开发自定义标签问题!package tagPackage;
import java.io.*;
import javax.jsp.JspException;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.jstl.*;
public class FileTag extends TagSupport{}
错误提示:
TagSupport cannot be resolved to a type
the import javax.servlet.jsp.tagext cannot be resolved to a type该怎么解决?我已经把JSTL.jar 包加入到了eclipse中了,是否还要加入其他的包?

解决方案 »

  1.   

    你好,制作taglib并不需要jstl.jar而是需要jsp-api.jar
    你可以在tomcat的common/lib目录下找到这个包。制作简单的taglib,可以参考我们教程中的例子:http://www.family168.com/tutorial/jsp/html/jsp-ch-09.html
      

  2.   

    regtld/Protld.java
     
    package regtld;
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.tagext.TagSupport;
    import javax.servlet.jsp.JspWriter;
    import properties.RegProperties;
    public class Protld extends TagSupport {
     private String temp;
     public void setTemp(String temp){
      this.temp=temp;
     }
     public int doEndTag() throws JspException {
      // TODO 自动生成方法存根
      JspWriter out=pageContext.getOut();
      try{
    //new RegProperties().getProperties(temp)自定义的一个从register.properties文件中读取数据的类方法
       out.print(new RegProperties().getProperties(temp));
      }catch(Exception e){
       System.err.println(e);
      }
      return super.doEndTag();
     } 

    foot.jsp
     
    <%@page pageEncoding="GB2312"%>
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@taglib uri="/reg" prefix="reg" %>
    <table width="800" border="1" align="center" bordercolor="#FF9900">
      <tr>
        <td height="20" bgcolor="#FF9900">&nbsp;</td>
      </tr>
      <tr>
        <td height="100" align="center" valign="middle" bgcolor="#F0F0F0"><p>版权所有:
          <reg:protld temp="copyright" /></p>
        <p>技术支持:<reg:protld temp="designer" /></p></td>
      </tr>
    </table>
     
     
    web.xml
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
     <display-name>Register</display-name>
     <description>design by xiang</description> <welcome-file-list>
      <welcome-file>/index.jsp</welcome-file>
     </welcome-file-list>
     
     <session-config>
      <session-timeout>30</session-timeout>
     </session-config>
     
     <taglib>
      <taglib-uri>/reg</taglib-uri>
      <taglib-location>/WEB-INF/tld/reg.tld</taglib-location>
     </taglib>
    </web-app>标签库reg.tld
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib
            PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
            "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
     <tlib-version>1.0</tlib-version>
     <jsp-version>1.2</jsp-version>
     <short-name>tld</short-name>
     <uri>/reg</uri>
     <tag>
      <name>protld</name>
      <tagclass>regtld.Protld</tagclass>
      <bodycontent>empty</bodycontent>
      <info>Display title</info>
      <attribute>
       <name>temp</name>
       <required>true</required>
       <rtexprvalue>false</rtexprvalue>
       <type>String</type>
      </attribute>
     </tag>
    </taglib>以前做的一个实验的例子
    希望对你有帮助同楼上
    制作taglib并不需要jstl.jar