0x01 环境搭配

如果还不会搭建jsp环境的可以按照下面的文章跟着搭建

Mac版IDEA创建maven web项目-详细过程: https://www.yuque.com/pmiaowu/gpy1q8/npv0fr

0x02 安装JSTL库

0x02.1 maven安装JSTL库

0x02.1.1 安装JSTL

打开: https://mvnrepository.com/
搜索: JSTL
点进去: https://mvnrepository.com/artifact/javax.servlet/jstl
image.png
我这里选择1.2
image.png

打开: https://mvnrepository.com/artifact/javax.servlet/jstl/1.2

  1. <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
  2. <dependency>
  3. <groupId>javax.servlet</groupId>
  4. <artifactId>jstl</artifactId>
  5. <version>1.2</version>
  6. </dependency>

image.png
image.png

0x02.1.2 安装taglibs

打开: https://mvnrepository.com/
搜索: taglibs
点进去: https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl
image.png
我这里选择1.2.5
image.png

打开: https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl/1.2.5

  1. <!-- https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl -->
  2. <dependency>
  3. <groupId>org.apache.taglibs</groupId>
  4. <artifactId>taglibs-standard-impl</artifactId>
  5. <version>1.2.5</version>
  6. <scope>runtime</scope>
  7. </dependency>

image.png

0x02.2 手动安装JSTL库

0x02.2.1 JSTL包下载

首先介绍如何手动下载jar包
打开: https://mvnrepository.com/artifact/javax.servlet/jstl/1.2
下载: https://repo1.maven.org/maven2/javax/servlet/jstl/1.2/jstl-1.2.jar
image.png

0x02.2.2 taglibs包下载

打开: https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl/1.2.5
image.png

打开: https://repo1.maven.org/maven2/org/apache/taglibs/taglibs-standard-impl/1.2.5/
下载: https://repo1.maven.org/maven2/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar
image.png

0x02.2.3 导入JSTL包与taglibs包

jstl-1.2-sources.jartaglibs-standard-impl-1.2.5.jar下载到本地以后
把这两个文件拷贝到 /WEB-INF/lib/下就可以了
如果WEB-INF下面没有lib文件夹,那就自己创建个lib文件夹
image.png
image.png

0x03 测试小例子

  1. // 目录结构
  2. ├── src
  3. └── main
  4. └── webapp
  5. └── com
  6. └── ...
  7. └── WEB-INF
  8. └── web.xml
  9. ├── ...
  10. └── JSTL库测试
  11. ├── test1.jsp
  1. // 文件地址: ./src/main/webapp/JSTL库测试/
  2. // 文件名称: test1.jsp
  3. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  4. <%--引入对应标签--%>
  5. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  6. <html>
  7. <head>
  8. <title>JSTL库测试-1</title>
  9. </head>
  10. <body>
  11. <c:out value="&lt要显示的数据对象(未使用转义字符)&gt" escapeXml="true" default="默认值"></c:out>
  12. </body>
  13. </html>
  14. // 打开: http://127.0.0.1:8081/mavenJspTest_war/JSTL库测试/test1.jsp

image.png