Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

JSTL Tags มีกี่ประเภท?

JSTL (JSP Standard Tag Library) แบ่ง tags ตามฟังก์ชันเป็น 5 กลุ่ม:

กลุ่มPrefix แนะนำURIคำอธิบาย
Core Tags c https://java.sun.com/jsp/jstl/core ควบคุม flow: if, choose, forEach, forTokens, set, remove, catch, out, url, redirect, import
Formatting Tags fmt https://java.sun.com/jsp/jstl/fmt จัดรูปแบบ: formatNumber, formatDate, parseNumber, parseDate, bundle, message, requestEncoding, timeZone
SQL Tags sql https://java.sun.com/jsp/jstl/sql Database: query, update, transaction, param, dateParam, setDataSource
XML Tags x https://java.sun.com/jsp/jstl/xml XML: parse, out, set, if, choose, forEach, transform, param, import
JSTL Functions fn https://java.sun.com/jsp/jstl/functions String functions: length, contains, substring, replace, split, join, escapeXml, toUpperCase, etc.

การใช้งาน

ต้อง import taglib ก่อนใช้แต่ละกลุ่ม:

<%@ taglib prefix="c" uri="https://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="https://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="https://java.sun.com/jsp/jstl/functions" %>

การติดตั้ง JSTL (Tomcat)

  1. ดาวน์โหลดจาก Apache Standard Taglib
  2. คัดลอก JAR files (jstl.jar, standard.jar) ไป WEB-INF/lib/

JSTL ช่วยลด scriptlets ทำให้ JSP สะอาด อ่านง่าย และปลอดภัยกว่า