2

我正在将旧版 Web 应用程序移植到 JBOSS AS7。该代码在 Tomcat 6 或 JBOSS 5 中运行良好。该应用程序使用 struts-1.2.9,我们还定义了一些自定义 taglib,这给我带来了问题。

我有一个定义 taglib 的 mainScripts.jsp 文件

<%@ taglib uri="/WEB-INF/lib/abtaglib.tld" prefix="abtag" %>

/WEB-INF/web.xml 文件包括以下内容。不确定这是否需要!?

<taglib>
    <taglib-uri>abtags</taglib-uri>
    <taglib-location>/WEB-INF/lib/abtaglib.tld</taglib-location>
</taglib>

当我在 JBOSS AS7 中访问此页面时,我收到以下错误。似乎 jboss web 模块无法访问我的 war 文件中的文件。我怎样才能解决这个问题?

10:04:53,881 DEBUG [org.apache.struts.taglib.tiles.InsertTag] (http-localhost/127.0.0.1:8080-1) insert page='/WEB-INF/jsps/mainScripts.jsp'.
10:04:53,991 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/web].[jsp]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet jsp threw exception: org.apache.jasper.JasperException: JBWEB004036: File "/WEB-INF/lib/abtaglib.tld" not found
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:53) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:147) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:147) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:385) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:446) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1372) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Parser.parse(Parser.java:132) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:256) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:105) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:359) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:339) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:326) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:606) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:832) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:718) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:655) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:940) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:607) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:760) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:892) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462) [struts-1.2.9.jar:1.2.9]
    at org.apache.jsp.WEB_002dINF.common.mainLayout_jsp._jspx_meth_tiles_005finsert_005f0(mainLayout_jsp.java:482)
    at org.apache.jsp.WEB_002dINF.common.mainLayout_jsp._jspService(mainLayout_jsp.java:149)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:832) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:620) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:553) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:482) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241) [struts-1.2.9.jar:1.2.9]
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) [struts-1.2.9.jar:1.2.9]
    at com.sprint.struts.action.StrutsServlet.process(StrutsServlet.java:67) [classes:]
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [struts-1.2.9.jar:1.2.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35]
4

3 回答 3

2

我找到了解决方案。似乎位于 JBOSS 模块 (jbossweb-7.2.0.Final-redhat-1.jar) 中的 Jasper 无法访问位于 /WEB-INF/lib/ 中的我的 tld 文件。相同的代码适用于 JBOSS 5、Websphere 6 和任何版本的 Tomcat。我认为这是一个类加载问题。当我将 tld 文件移动到 jar 文件中的 /META-INF 文件夹中时,它开始工作。我不再需要 web.xml 中的 taglib 引用,因为 tld 文件是自动从 jar 文件 /META-INF 文件夹中提取的。这是最终的代码:

在jsp中声明taglib:

<%@ taglib uri="http://mycompany/abtags" prefix="abtag" %>

将 tld 文件打包到 jar 中:

/WEB-INF/lib/XYZ.jar

XYZ.jar 内容:

/META-INF/abtaglib.tld
/META-INF/MANIFEST.MF

abtaglib.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>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.1</jsp-version>
    <short-name>abtag</short-name>
    <uri>http://mycompany/abtags</uri>
    <display-name>XYZ Tag</display-name>
...
于 2013-07-05T18:53:01.647 回答
1

我在使用 Jboss 8(Wildfly 8)时遇到了同样的问题。将所有 taglib "*.tld" 文件复制到 META_INF 文件夹中,为我工作。

于 2016-04-27T07:16:53.317 回答
0

您应该使用在您的 tld 文件中定义的 URI,并且,是的,在您的 web.xml 中定义它的位置。例如 :

<%@ taglib uri="http://mycompany/jsp/abtablib" prefix="abtag" %>

如果您使用的是标准标记库,只需将 jar 放入您的类路径并使用正确的 URI。这是一个带有核心 jstl taglib 的示例(将 jstl-1.2.jar 放入您的类路径中):

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
于 2013-07-05T13:36:13.970 回答