Getting trouble in installing tag lib in Apache tomcat7

前端 未结 3 1225
予麋鹿
予麋鹿 2021-02-06 14:43

I have application and I want to use jstl tag lib.

I have two jars JSTL.jar and standard.jar. I put both in my WEB-INF/lib

相关标签:
3条回答
  • 2021-02-06 15:12

    You made several mistakes:

    • You should not manually redefine JAR's own taglibs in web.xml. This is a myth.
    • You should be using a Servlet 3.0 compatible web.xml for Tomcat 7.
    • You should be using JSTL 1.2, not 1.0.

    Remove them all. Remove all <taglib> from web.xml. Remove the both JARs from /WEB-INF/lib. Then follow the following steps:

    1. Download jstl-1.2.jar and drop it in /WEB-INF/lib.
    2. Fix your web.xml to be Servlet 3.0 compatible.

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app 
          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-app_3_0.xsd"
          version="3.0">
      
          <!-- Config here. No taglibs! -->
      
      </web-app>
      
    3. Use the documented taglib declaration:

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

    See also:

    • Our JSTL wiki page

    I have a vague suspicion that you're using Roseindia.net as a Java EE resource. Your invalid approach is also mentioned in there. You should not do that. You should put that site in your Internet blacklist. This site is so full of bad answers and bad practices. Use Oracle's official resources instead, or Stackoverflow.com of course.

    0 讨论(0)
  • 2021-02-06 15:12

    You don't need to configure taglibs in web.xml anymore. Plus you're defining different taglib urls (iirc the web.xml ones are correct).

    Use the uris from your web.xml in the jsp and remove the web.xml taglib defs.

    0 讨论(0)
  • 2021-02-06 15:19

    If you are one of the lucky few that have to support old code and removing taglib in your web.xml is not an option. You can enclose it in <jsp-config> like so:

    <jsp-config>
      <taglib>
        <taglib-uri>/taglibs/custom-taglib</taglib-uri>
        <taglib-location>/WEB-INF/custom-taglib.tld</taglib-location>
      </taglib>
    </jsp-config>
    
    0 讨论(0)
提交回复
热议问题