向JSP添加自定义标记库时出现异常

时间:2015-04-19 07:09:13

标签: java jsp java-ee glassfish jstl

我差不多2年前遇到与this unanswered question相同的问题。

<%@ taglib uri="/WEB-INF/tlds/myLib" prefix="myLib" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

我的JSP中有这两行。最初我只使用JSTL核心库,一切运行良好。一旦我添加了一个自定义库,我就会得到一个像这样的例外:

java.lang.NullPointerException
at org.apache.jasper.compiler.TagLibraryInfoImpl.toString(TagLibraryInfoImpl.java:129)
at java.lang.String.valueOf(String.java:2979)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at java.util.concurrent.ConcurrentHashMap.toString(ConcurrentHashMap.java:1321)
at org.apache.taglibs.standard.tag.common.core.OutSupport.out(OutSupport.java:211)
at org.apache.taglibs.standard.tag.common.core.OutSupport.doStartTag(OutSupport.java:132)
at org.apache.jsp.FormTest_jsp._jspx_meth_c_out_3(FormTest_jsp.java:306)
at org.apache.jsp.FormTest_jsp._jspx_meth_c_forEach_1(FormTest_jsp.java:256)
at org.apache.jsp.FormTest_jsp._jspService(FormTest_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
at form.FormServlet.processRequest(FormServlet.java:60)
at form.FormServlet.doPost(FormServlet.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)

如果我删除两个taglib指令中的任何一个,一切都能正常工作。

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>mylib</short-name>
  <uri>/WEB-INF/tlds/myLib</uri>
  <tag>
    <name>beaner</name>
    <tagclass>form.BeanTagHandler</tagclass>
    <bodycontent>empty</bodycontent>
  </tag>
</taglib>

tld非常小,试图让这个工作。

如果有人能够提供一些有关问题的见解,我将不胜感激。感谢。

编辑:发现问题的根源。

<table>
<tr>
<th>Attribute Name</th>
<th>Attribute Value</th></tr>
<c:forEach var="a" items="${applicationScope}">
<tr>
<td> <c:out value="${a.key}"/> </td>
<td> <c:out value="${a.value}" /> </td>
</tr>
</c:forEach>
</table>

有问题的部分是c:out for $ {a.value}。没有它,jsp工作得很好。 出于某种原因,当我不导入自定义标记库时,它可以正常工作。关于为什么试图c:outSappScope的值会导致问题的任何想法?

1 个答案:

答案 0 :(得分:1)

好吧我弄明白了这个问题。 applicationScope中有一个名为com.sun.jsp.taglibraryCache的属性,它是Class ConcurrentHashMap。似乎导入另一个标记库会导致类的toString方法产生NullPointerException。我通过使用c:catch来捕获异常来解决我的问题。