2009-10-27 72 views
0

当我尝试运行带有自定义jsp标记的jsp页面时,出现以下错误。Jsp自定义标记问题

javax.servlet.ServletException:/pages/editBidForm.jsp(43,3)无标签 “的getName” 与前缀 “定制” org.apache.struts2.dispatcher.Dispatcher.serviceAction进口标签库定义(分派的.java:515) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) .... ...

这是我在JSP页面代码(部分)。

<%@ taglib uri="/WEB-INF/taglib.tld" prefix="custom" %> 
    <tr> 

      <custom:getName name="Narayana Hari"/> 

       </tr> 

而且taglib.tld文件

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag 
Library 1.2//EN" 
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> 
<taglib> 
     <tlibversion>1.0</tlibversion> 
     <jspversion>1.1</jspversion> 
     <shortname>custom</shortname> 
    <tag> 
     <name>hello</name> 
     <tagclass>com.poran.action.CustomizedTag</tagclass> 
     <bodycontent>empty</bodycontent> 
     <info>Tag having no body</info> 
     <attribute> 
     <name>name</name> 
     <required>true</required> 
     <rtexpvalue>true</rtexpvalue> 
     </attribute> 

和Java类

package com.poran.action; 

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

import java.util.*; 

public class CustomizedTag implements Tag { 
    private PageContext pageContext; 
    private Tag parent; 
    private String name; 





    public String getName() { 
    return name; 
    } 

    public void setName(String name) { 
    this.name = name; 
    } 

/* public CustomizedTag() { 
     super(); 
    } 
*/ 
    public int doStartTag() throws JspException { 
    /* try { 
     pageContext.getOut().print(getName()); 
     } catch (IOException ioe) { 
     throw new JspException("Error:"+ioe.getMessage()); 
     }*/ 
     return SKIP_BODY; 
    } 

    public int doEndTag() throws JspException { 
     return SKIP_PAGE; 
    } 
    public void release() { 
    } 

public Tag getParent() { 
    // TODO Auto-generated method stub 
    return null; 
} 

public void setPageContext(PageContext arg0) { 
    // TODO Auto-generated method stub 

} 

public void setParent(Tag arg0) { 
    // TODO Auto-generated method stub 

} 

    /* public void setPageContext(PageContext pageContext) { 
     this.pageContext = pageContext; 
    } 

    public void setParent(Tag parent) { 
     this.parent = parent; 
    } 

    public Tag getParent() { 
     return parent; 
    }*/ 

} 

请建议我在哪里纠正。

感谢, 阿迪亚[R

回答

1

你已经在你的taglib定义的唯一标签(在你的代码看)是“你好”。你如何尝试将其更改为<name>getName</name>

+0

非常感谢。我没有正确理解标签。这解决了我的问题。 :) – 2009-10-27 06:53:22