cannot load JSTL taglib within embedded Jetty server

后端 未结 10 741
太阳男子
太阳男子 2020-12-10 11:55

I am writing a web application that runs within an embedded Jetty instance.

When I attempt to execute a JSTL statement, I receive the following exception:

相关标签:
10条回答
  • 2020-12-10 12:33
    • jstl-1.2.jar
    • standard-1.1.2.jar

    This collides. Remove the standard-1.1.2.jar. You should use standard-1.1.2.jar only with jstl-1.1.2.jar. Since JSTL 1.2 the standard JAR has been merged into JSTL JAR, resulting in a single jstl-1.2.jar file.

    0 讨论(0)
  • 2020-12-10 12:33

    I had the same problem and found out that http://java.sun.com/jsp/jstl/core is regarded as the single system URI and all taglib definitions that try to define it are ignored (but when referenced, an error occurs anyway).

    I used the following before starting the Jetty and now it works:

    try {
        Field f = TldScanner.class.getDeclaredField("systemUris");
        f.setAccessible(true);
        ((Set)f.get(null)).clear();
    } catch (Exception e) {
        throw new RuntimeException("Could not clear TLD system uris.",e);
    }
    
    0 讨论(0)
  • 2020-12-10 12:37

    @Drew Thanks Drew. It works.I had been googling for this and end up here.What my mistake was : I was using

                     <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>jstl</artifactId>
                         <version>1.1.2</version>
                         <scope>provided</scope>
                    </dependency>
    

    I changed it from above to

               <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                 <version>1.2</version>
                 <scope>provided</scope>
            </dependency>
    

    and it got working. Also I was using jstls dependency which I removed.

    0 讨论(0)
  • 2020-12-10 12:38

    I also had the same problems. I fixed it by adding the below code:

    public static final String[] TLD_JAR_NAMES = new String[]{"sitemesh", "spring-webmvc", "shiro-web", "springside-core"};
    ...
    JettyFactory.setTldJarNames(server, TLD_JAR_NAMES);
    

    Maybe you can try it. Please replace TLD_JAR_NAMES with your real TLD Jar names.

    0 讨论(0)
  • 2020-12-10 12:42

    Jetty 8.0, which has pushed as the default when you use jetty:run, has servlet API 3.0. As of that version of the standard, JSTL standard is supposed to be included, and these taglibs cannot be in the webapp classpath, only the standard classpath. However, 8.0.0.M0 forgot to include them.

    Specifying 7.1.4.v20100610 helped for me.

    0 讨论(0)
  • 2020-12-10 12:42

    In your web.xml, try changing "h77p://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" to start with "http://" and see if that fixes the error.

    However, that may not be the underlying cause, since I had that same error when using jetty-maven-plugin and JSTL taglib header in my JSP:

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

    PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

    I'm using an out-of-the-box Spring MVC template from SpringSource Tool Suite, so am not sure why the Maven plugin for Jetty chokes on it.

    <build>
       <plugins>
          <plugin>
             <groupId>org.mortbay.jetty</groupId>
             <artifactId>jetty-maven-plugin</artifactId>
          </plugin>
       </plugins>
    </build>
    <repositories>
         <repository>
           <id>maven2-repository.dev.java.net</id>
           <name>Java.net Repository for Maven</name>
           <url>http://download.java.net/maven/2/</url>
           <layout>default</layout>
         </repository>
    </repositories>
    

    And only javax.servlet:jstl:1.2 is listed in my POM's dependencies, since it now obsoletes taglibs:standard:1.1.2, which was a suggestion given above.

    0 讨论(0)
提交回复
热议问题