How to use taglibs JSTL/core with JAR in WEB-INF folder

若如初见. 提交于 2019-12-10 19:16:09

问题


Currently I have taglibs set up and working correctly using the following tag at the top of my JSP pages:

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

In Maven I have the dependencies:

<dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency> 

I need my web app to work without Internet connection i.e. not calling the URI in the taglib so I thought I could download the jstl-1.2.jar and put it in /WEB-INF/lib folder. Then I could have my tag as the following:

<%@ taglib uri="/WEB-INF/lib/jstl-1.2" prefix="c" %>

However, this is not working. It says that the tag library descriptor cannot be found. So my question is, how do I use JSTL in taglibs using a JAR in the WEB-INF folder, instead of calling the java sun website in the URI??

Do I need to put anything in web.xml? Do I remove my Maven dependencies? Do I need to put something in META-INF?

Any help would be much appreciated! Thanks!


回答1:


The URI in

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

is not really a reference to the internet. Even after putting the Jar file in WEB-INF/lib/ you will leave the uri as that address. The servlet container is always looking for the jar in WEB-INF/lib/ and never downloads it from http://java.sun.com/jsp/jstl/core. That URI is more like a unique name identifying the taglib.

Check for yourself by clicking the link to http://java.sun.com/jsp/jstl/core There is no jar file to download there. Its just an identifier.



来源:https://stackoverflow.com/questions/23118772/how-to-use-taglibs-jstl-core-with-jar-in-web-inf-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!