jsp自定义标签问题

发布于 2024-08-09 05:01:16 字数 2743 浏览 2 评论 0原文

当我尝试使用自定义 jsp 标记运行 jsp 页面时,出现以下错误。

javax.servlet.ServletException:/pages/editBidForm.jsp(43,3) 在使用前缀“custom”导入的标签库中没有定义标签“getName” org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.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

I'm getting the following error when I try to run a jsp page with a custom jsp tag.

javax.servlet.ServletException: /pages/editBidForm.jsp(43,3) No tag "getName" defined in tag library imported with prefix "custom"
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
....
...

Here is my code(part) in the jsp page.

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

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

               </tr>

And the taglib.tld file

<?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>

And the java class

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;
   }*/

}

Please suggest me where to correct.

Thanks,
Aditya R

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强辩 2024-08-16 05:01:16

您在标记库中定义的唯一标记(查看您的代码)是“hello”。您尝试将其更改为 getName 怎么样?

The only tag you have defined in your taglib (looking at your code) is "hello". How about you try to change it to <name>getName</name>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文