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". What needs to be fixed here?
因此,我正在尝试创建自定义标记以显示当前日期的示例。我做了示例中所述的所有内容,但在启动我的服务器时抛出错误:没有为“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 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:
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>
1 个解决方案
#1
0
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.
好吧我明白了。我没有在Deployment Descriptor中对您的自定义标记执行“静态引用”,而是尝试从JSP页面本身动态引用它并且它有效。
#1
0
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.
好吧我明白了。我没有在Deployment Descriptor中对您的自定义标记执行“静态引用”,而是尝试从JSP页面本身动态引用它并且它有效。