Tomcat 7 and JSTL

前端 未结 9 1575
执念已碎
执念已碎 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 21:59

    I have been fighting with this for several hours. Here is a complete solution.

    1. I am using Tomcat 7, which is a Servlet 3.0-compliant server.

    2. If you desire to use the Servlet 3.0 spec, you must have your web.xml as follows:

       
      
    3. If you're using Maven, your pom.xml should have these lines.

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

      These dependencies are very important. JSTL 2.1 + Tomcat 7 + Servlet 3.0 is very broken unless you fix it by using these lines, especially the exclusion part. What is happening is the JSTL 2.1 Jars are actually pulling in the wrong versions of the Servlet spec--2.5. Unless you stop that from happening, you will be in a whole world of pain. A special thanks to Mr. Murray Todd Williams for these insights .

    4. Finally, in case Maven can't find those JARS, you can make Eclipse happy by including three JARS with your project and doing the usual Project--> Properties--> Java Build Path and include them that way--though Maven should take care of it.

      javax.servlet-api-3.0.1.jar
      javax.servlet.jsp.jstl-1.2.1.jar
      javax.servlet.jsp.jstl-api-1.2.1.jar
      
    5. Please note! This exact configuration only applies if you are using the magic combination of:

      1. A Servlet 3.0-compliant application server such as Tomcat 7

      2. Your web.xml has the right namespace for the Servlet 3.0 spec

      3. You have those three JARS and no other JSTL or Servlet JARS on your classpath.

    6. Make sure you do not place copies of these JARs in your WEB-INF/lib directory because they would in that case be sent to the server thereby causing LinkageErrors.

    7. In your JSP, you need to have this PRECISE line, formatted exactly as I have it or else Eclipse will whine that it doesn't recognize the c:blah tags:

      <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
      
    8. What a danged PITA! This is MUCH harder to implement than any other version of JSTL. This is the only example of something getting much more complicated rather than simpler in later iterations.

提交回复
热议问题