简体   繁体   English

自定义 JSP 标签错误:没有找到“taglib”的子翻译器

[英]Custom JSP tag error: did not find a Child Translator for “taglib”

So I am trying to work on a sample of creating a Custom tag to display current date.因此,我正在尝试创建一个自定义标签以显示当前日期的示例 I did everything stated in the example, but on starting my server its throwing an error: did not find a Child Translator for "taglib".我做了示例中所述的所有操作,但是在启动我的服务器时它抛出了一个错误:没有找到“taglib”的子翻译器。 What needs to be fixed here?这里需要修复什么?

Caused by: org.eclipse.jst.j2ee.commonarchivecore.internal.exception.ArchiveWrappedException
    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:167)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.open(DeployedModuleImpl.java:237)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.initialize(DeployedModuleImpl.java:436)
    ... 53 more
Caused by: org.eclipse.jst.j2ee.commonarchivecore.internal.exception.DeploymentDescriptorLoadException: WEB-INF/web.xml
    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.WARFileImpl.getDeploymentDescriptor(WARFileImpl.java:147)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.WARFileImpl.getStandardDeploymentDescriptor(WARFileImpl.java:301)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getDeploymentDescriptor(EARFileImpl.java:401)
    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:165)
    ... 55 more
Caused by: java.lang.IllegalStateException: Parent Translator (WebAppTranslator(web-app,1971221886)) did not find a Child Translator for "taglib".

web.xml declaration is: web.xml 声明为:

<taglib>
 <taglib-uri>myTags</taglib-uri>
 <taglib-location>/WEB-INF/lib/DateTagLib.tld</taglib-location>
</taglib>

TLD file:顶级域名文件:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<taglib>
   <tlibversion>1.0</tlibversion>
   <info>Custom Date Tag</info>

  <tag>
    <name>displayDate</name>
    <tagclass>com.demo.DateTag</tagclass>
    <bodycontent>empty</bodycontent>
    <info>Display Date</info>
  </tag>    

Tag Class:标签 Class:

package com.demo;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;

import java.io.IOException;
import java.text.*;
import java.util.*;

public class DateTag extends TagSupport {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public int doStartTag() throws javax.servlet.jsp.JspException {
        HttpServletRequest req;
        Locale locale;
        HttpJspPage g;
        DateFormat df;
        String date;
        JspWriter out;

        req = (HttpServletRequest) pageContext.getRequest();
        locale = req.getLocale();
        df = SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL, locale);
        date = df.format(new java.util.Date());  

        try {
            out = pageContext.getOut();
            out.print(date);
            } catch(IOException ioe){
                throw new JspException("IO Error: " + ioe.getMessage());
            } //end try/catch

            return Tag.SKIP_BODY;

    } //end doStarttag

} //end DateTag

</taglib>

Well I figured it out.好吧,我想通了。 Instead of doing a "static reference" to your custom tag in Deployment Descriptor, I tried referencing it dynamically from the JSP page itself and it worked.我没有在部署描述符中对您的自定义标签进行“静态引用”,而是尝试从 JSP 页面本身动态引用它并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM