<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="fuyou" uri="/WEB-INF"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
  </head>
  <% String name="fuyoubao";
     String value="zhenping";
  %>
  <body>
   <fuyou:list name="zhenping" n1="fuyou" n2="zp" n3="fyb" n4="fyj"/>
  <!-- 如果把下面这行注释了,它就正常运行,显示下拉列表 -->
   <fuyou:list <%=name%>=<%=zhenping%> n1="fuyou" n2="zp" n3="fyb" n4="fyj"/>
  </body>
</html>package com.fuyou;import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.TagSupport;public class ListTag extends TagSupport implements DynamicAttributes { private String name = "";
private HashMap map = new HashMap();

public void setName(String name){
this.name  = name;
 
}
public void setDynamicAttribute(String uri, String locaName, Object value)
throws JspException {
System.out.println(uri); //这里打出来的null,uri是指什么
 map.put(locaName, value); }
public int doStartTag()throws JspException{
 JspWriter out = pageContext.getOut();
  Set list = map.entrySet();
  try{
  out.print("<select name='"+name+"'>");
  Iterator it = list.iterator();
  while(it.hasNext()){
 Map.Entry entry = (Map.Entry)it.next();
 out.print("<option value='");
 out.print(entry.getKey());
 out.print("'>");
 out.print(entry.getValue());
 out.println("</option>");
  
  }
out.print("</select>");
  }catch(IOException e){
 e.printStackTrace();
  }
return super.doStartTag();

}}<?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    <description>A tag library exercising SimpleTag handlers.</description>
    <tlib-version>1.0</tlib-version>
    <short-name>fuyous</short-name>
    <uri>/WEB-INF</uri>
    
    <tag>
      <name>viewIp</name>
      <tag-class>com.fuyou.ViewIpTag</tag-class>
      <body-content>empty</body-content>
    </tag>
     
     <tag>
      <name>list</name>
        <tag-class>com.fuyou.ListTag</tag-class>
        <body-content>empty</body-content>
         <attribute>
            <name>name</name>
            <required>true</required>
         </attribute>
         <dynamic-attributes>true</dynamic-attributes>
        </tag>
</taglib>

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【fuyou001】截止到2008-07-18 16:38:50的历史汇总数据(不包括此帖):
    发帖的总数量:160                      发帖的总分数:4325                     每贴平均分数:27                       
    回帖的总数量:993                      得分贴总数量:372                      回帖的得分率:37%                      
    结贴的总数量:159                      结贴的总分数:4295                     
    无满意结贴数:19                       无满意结贴分:745                      
    未结的帖子数:1                        未结的总分数:30                       
    结贴的百分比:99.38 %               结分的百分比:99.31 %                  
    无满意结贴率:11.95 %               无满意结分率:17.35 %                  
    值得尊敬
      

  2.   

    uri知道了,我的问题是 :<!-- 如果把下面这行注释了,它就正常运行,显示下拉列表 -->
       <fuyou:list <%=name%>=<%=zhenping%> n1="fuyou" n2="zp" n3="fyb" n4="fyj"/>
      </body>
    这样写就不对,控制台报下面的错:
    2008-7-18 16:21:46 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet jsp threw exception
    org.apache.jasper.JasperException: /index.jsp(27,15) Unterminated &lt;fuyou:list tag
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
      

  3.   

    up,我对<进行转义了没有用,还报错