0

I'm trying to test JSP tags that are defined as .tag files in my application's WebContent directory. The webproject layout is as follows:

  • Project
  • WebContent
    • WEB-INF
      • tags
        • tag1.tag
      • views
        • tagTest.jsp

Using standalone jetty, I'm trying to load test jsp. tagTest.jsp is just a wrapper over the tagfile and invokes it using tagdir attribute like:

<%@ taglib prefix="test" tagdir="/WEB-INF/tags" %>
<test:tag1 model="${cat}" />

I have setup the server like this:

WebAppContext webCtx = new WebAppContext();
webCtx.setContextPath("/jsptest");
webCtx.setDescriptor("WebContent/WEB-INF/test-web.xml");

webCtx.setResourceBase("WebContent");

ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { webCtx });
server.setHandler(contexts);

I have set up a servlet that forwards the request to test jsp since I was not able to invoke jsp from subdirectory of WebContent directly:

    request.setAttribute("cat", new SomeModel());
    getServletContext().getRequestDispatcher("/WEB-INF/views/tagTest.jsp").forward(request, response);

Invoking this servlet gives following error (also same error if I copy test jsp directly under WebContent and invoke as /jsptest/tagTest.jsp)

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:634)
at org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:280)
at org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:660)
at org.apache.jasper.compiler.TagFileProcessor.access$000(TagFileProcessor.java:91)
at   org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:719)
...

Caused by: java.lang.NullPointerException
at org.apache.taglibs.standard.tlv.JstlBaseTLV.validate(JstlBaseTLV.java:149)
at org.apache.taglibs.standard.tlv.JstlCoreTLV.validate(JstlCoreTLV.java:105)
at org.apache.jasper.compiler.TagLibraryInfoImpl.validate(TagLibraryInfoImpl.java:949)
at org.apache.jasper.compiler.Validator.validateXmlView(Validator.java:1921)
at org.apache.jasper.compiler.Validator.validate(Validator.java:1888)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:223)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)

How to configure JSP with jetty embedded that have tagdir tags? Do I need to have a war if tagdir's are used? Regular jsp is getting loaded fine, tag uri is getting resolved correctly:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> - this works
uɐɪ
  • 2,540
  • 1
  • 20
  • 23
susmit shukla
  • 213
  • 4
  • 14
  • Could you show us the tag file? – JB Nizet Aug 31 '11 at 18:17
  • 1
    What's the target container make/version? What's the `web.xml` version? What's the JSTL version? (your JSTL URI is very obsolete, it's of the very first JSTL prototype version over a decade ago) – BalusC Aug 31 '11 at 18:36
  • I'm using Jetty 8.0 RC0 - servlet 3.0 and jsp 2.2. Web.xml is version 2.5. I have put all the jsp jars from jetty home/lib in the classpath. It is able to resolve and load taglibs with uri attribute properly but the issue I'm facing is only with local tags included using tagdir and relative path under WEB-INF/tags – susmit shukla Aug 31 '11 at 19:31
  • This question is not about embedded programming, retagged. See http://stackoverflow.com/tags/embedded/info – uɐɪ Sep 01 '11 at 10:35

2 Answers2

0

Depending on the version of jetty you are using, you may need to enable scanning of TLD.

I use Jetty 7 and I did enabled it by setting an attribute on the context where I want to use tag libs:

webCtx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", 
    ".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$");

Refer to http://wiki.eclipse.org/Jetty/Howto/Configure_JSP#Using_JSTL_Taglibs_for_Jetty_7.x_and_8.x

On my project (using maven), I have standard TLDs are on the JAR "org.apache.taglibs.standard.glassfish-1.2.0.v2011120803.jar" and theoretically it would be enough to use as value for ContainerIncludeJarPattern the following pattern:

".*/org\\.apache\\.taglibs\\.standard\\.glassfish-1\\.2\\.0\\.v201112081803\\.jar"

It actually works and it is a confirmation of where do jetty found the tag libs, but I've preferred to leave the previous pattern which I found on the wiki.eclipse.org page linked above.

It may be required to extend the pattern if you want to include custom tag libs.

0

The proper JSTL core taglib declaration is

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

Try with this one and see if it solves the problem.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Note that this only works when OP is *actually* using JSTL 1.1 or newer. If OP is *actually* using JSTL 1.0, then that URI won't work. Also note that JSTL 1.0 ships with EL resolver builtin which would not work nicely together with Servlet 2.4 / JSP 2.0 or newer which has taken over the EL resolving job. For a bit of history, see also http://stackoverflow.com/questions/4812755/difference-between-jsp-el-jsf-el-and-unified-el/4812883#4812883 – BalusC Aug 31 '11 at 18:45
  • Yes. Since the OP is using tag files, he's using JSP 2.0 and thus, normally, not JSTL 1.0. – JB Nizet Aug 31 '11 at 18:55
  • To debug, I started with a new web application project and made the layout as above and found that tagdir resolution is working and testJsp is served fine. The only difference is that real project has geronimo jasper/jstl jars too on the classpath and that might be interfering with the glassfish version of jars that Jetty uses. – susmit shukla Aug 31 '11 at 21:49