簡體   English   中英

自定義 JSP 標簽錯誤:沒有找到“taglib”的子翻譯器

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

因此,我正在嘗試創建一個自定義標簽以顯示當前日期的示例 我做了示例中所述的所有操作,但是在啟動我的服務器時它拋出了一個錯誤:沒有找到“taglib”的子翻譯器。 這里需要修復什么?

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 聲明為:

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

頂級域名文件:

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

標簽 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>

好吧,我想通了。 我沒有在部署描述符中對您的自定義標簽進行“靜態引用”,而是嘗試從 JSP 頁面本身動態引用它並且它有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM