Tomcat 7 and JSTL

前端 未结 9 1590
执念已碎
执念已碎 2020-11-28 21:35

I wrote a web application with Eclipse Tomcat and it works on my local Tomcat 7, when I tried to publish it online on a Tomcat 7, I had the following error:

9条回答
  •  孤独总比滥情好
    2020-11-28 22:00

    There are two answers here that are mostly correct with regard to how to solve this problem when using Maven when dealing with this issue. However, both are not 100% complete.

    Using Exclusions per @Tom Hunter's answer

    This answer works. However, there will still be log messages from Tomcat regarding duplicate TLD definitions. This is because both the jstl and jstl-impl artifacts include the TLD definitions. To remove those messages, I think a better Maven setup is this:

    
        1.2
        runtime
        javax.servlet.jsp.jstl
        jstl-api
        
            
                servlet-api
                javax.servlet
            
            
                jsp-api
                javax.servlet.jsp
            
        
    
    
    
        org.glassfish.web
        jstl-impl
        1.2
        runtime
        
            
                servlet-api
                javax.servlet
            
            
                jsp-api
                javax.servlet.jsp
            
            
                jstl-api
                javax.servlet.jsp.jstl
            
        
    
    

    This includes only the jstl api classes with the necessary exclusions to avoid the problems explained in the rest of that answer.

    Using newer POM versions per @George's answer

    It took me a while to realize it, but there are newer versions of the JSTL pom's available. It's really confusing because these newer packages use similar, but slightly different naming conventions. These newer versions mark the javax.servlet, javax.jsp, etc dependencies as provided scope so that they do not need to be excluded. The 1.2.1 version depends on a 1.2.1 version of the jstl-api. And so this would work as well as above answer:

    
        org.glassfish.web
        javax.servlet.jsp.jstl
        1.2.1
        runtime
    
    

    This differs slightly from George's answer because I changed scope to runtime. George specified scope as provided. With a provided scope, the jars would have to be copied manually in to the Tomcat lib directory, or some other dependency would have to included the necessary implementation.

    However, I could not find the 1.2.1 version of the impl in maven central, jboss repo, or any other repos. I ended up going around in circles and finally just used a local file based repo to store the jar. The dependency and jar are described here:

    • http://mvnrepository.com/artifact/org.glassfish.web/javax.servlet.jsp.jstl/1.2.1

提交回复
热议问题