>  기사  >  Java  >  자바의 JSTL

자바의 JSTL

WBOY
WBOY원래의
2024-08-30 16:21:02709검색

JSTL은 JSP(Java Server Pages)의 추가 확장인 Java Standard Tag Library로 축약됩니다. JSTL은 개발자를 위한 코드 줄을 줄였습니다. 이 JSTL은 조건부 및 반복과 같은 일반적인 작업인 구조적 작업을 지원합니다. 이러한 태그는 I18N(국제화) 태그, SQL 태그, XML 문서 등을 변경하는 데 사용됩니다. 이는 또한 Java 표준 태그 라이브러리 내에 기존 사용자 정의 태그를 연결하기 위한 프레임워크를 제공합니다.

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

JSTL의 장점:

  • 빠른 개발.
  • 코드 재사용성.
  • 스크립틀릿 태그를 사용할 필요가 없습니다.

JSTL은 Java에서 어떻게 작동하나요?

JSTL은 애플리케이션에서 사용한 태그 유형을 기반으로 작동합니다. 약 5가지 유형의 태그로 구성됩니다. 그들은

  1. 핵심 태그
  2. 함수 태그
  3. 태그 서식 지정
  4. XML 태그
  5. SQL 태그

JSTL 태그 설명:

Tag Type Description URI to include prefix
Core tags The JSTL core tag provides flow control, variable support, URL management etc. http://java.sun.com/jsp/jstl/core c
Function tags This function tag is used for String manipulation and
String length
http://java.sun.com/jsp/jstl/
functions
fn
Formatting tags This formatting tag is used for number, date and message formatting http://java.sun.com/jsp/jstl/fmt fmt
XML tags This XML tag is used for transformation and flow control etc. http://java.sun.com/jsp/jstl/xml x
SQL tags This SQL tag is used to provide support for SQL support.  http://java.sun.com/jsp/jstl/sql sql
태그 유형 설명 포함할 URI 접두사 핵심 태그 JSTL 핵심 태그는 흐름 제어, 변수 지원, URL 관리 등을 제공합니다. http://java.sun.com/jsp/jstl/core ㄷ 함수 태그 이 함수 태그는 문자열 조작 및
문자열 길이 http://java.sun.com/jsp/jstl/
기능 fn 태그 서식 지정 이 형식 태그는 숫자, 날짜 및 메시지 형식에 사용됩니다. http://java.sun.com/jsp/jstl/fmt fmt XML 태그 이 XML 태그는 변환 및 흐름 제어 등에 사용됩니다. http://java.sun.com/jsp/jstl/xml x SQL 태그 이 SQL 태그는 SQL 지원을 지원하는 데 사용됩니다.  http://java.sun.com/jsp/jstl/sql SQL

각 JSTL 태그는 다시 서로 다른 하위 태그로 구성됩니다. 이제 핵심 태그와 기능 태그의 몇 가지 예를 살펴보겠습니다.

참고: 다음 기능을 활용하세요. jstl.1.X.jar 파일을 사용해야 합니다. X는 버전을 나타냅니다.

아래 예시는 다음과 같습니다.

Eclipse의 프로젝트 구조:

자바의 JSTL

예 #1 – 핵심 태그 c:out

코드: NewFile.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<!--THis c:out tag is used for displaying output-->
<c:out value="${'Hello Amardeep, Wel come to EDUCBA online courses.'}" />
</body>
</html>

출력:

자바의 JSTL

예 #2 – 핵심 태그 세트 및 c:if 태그

코드: SetCIf.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:set var="money" scope="session" value="${5000*5}"/>
<c:if test="${money > 8000}">
<p>My Salary is: <c:out value="${money}"/><p>
</c:if>
</body>
</html>

출력:

자바의 JSTL

예 #3 – c:choose 태그가 포함된 코어 태그

코드: CChoose.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:set var="money" scope="session" value="${5000*5}"/>
<p>Your income is : <c:out value="${money}"/></p>
<c:choose>
<c:when test="${money <= 1000}">
You are paid with good salary.
</c:when>
<c:when test="${money > 10000}">
You are paid with really good salary.
</c:when>
<c:otherwise>
You are paid with low salary .
</c:otherwise>
</c:choose>
</body>
</html>

출력:

자바의 JSTL

예 #4 – c:when 태그가 포함된 핵심 태그

코드: CWhen.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:set value="214" var="digit"></c:set>
<c:choose>
<c:when test="${digit%2==0}">
<c:out value="${digit} is EVEN digit"></c:out>
</c:when>
<c:otherwise>
<c:out value="${digit} is ODD digit"></c:out>
</c:otherwise>
</c:choose>
</body>
</html>

출력:

자바의 JSTL

예 #5 – c:foreach 태그가 포함된 핵심 태그

코드: CForeach.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:forEach var="iterator" begin="100" end="110">
Count: <c:out value="${iterator}" />
<p>
</c:forEach>
</body>
</html>

출력:

자바의 JSTL

예 #6 – c:forTokens 태그가 있는 핵심 태그

코드: CForTokens.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:forTokens items="My-Name-is-Nathi-Paramesh" delims="-" var="del">
Word: <c:out value="${del}" />
<p>
</c:forTokens>
</body>
</html>

출력:

 자바의 JSTL

예 # 7 – c:redirect 태그가 포함된 핵심 태그

코드: CRedirect.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:set var="urlName" value="2" scope="request"/>
<c:if test="${urlName<1}">
<c:redirect url="http:/educba.com"/>
</c:if>
<!-- Page directly redirect to gmail because value is greater than 1 -->
<c:if test="${urlName>1}">
<c:redirect url="http://gmail.com"/>
</c:if>
</body>
</html>

출력:

 자바의 JSTL

예 #8 – c:contains 태그가 있는 함수 태그

코드: FunctionContains.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:set var="StringType"
value="We are learning online course from EDUCBA platform" />
<c:if test="${fn:contains(StringType, 'EDUCBA')}">
<h1 style="color: green">Yes Given String found in the value
</h1>
<p style="color:blue;border: 1px solid red;font-size:20px">JSTL abbreviated as Java Standard Tag Library. Which is
further extension for JSP (Java Server Pages). JSTL reduced the lines
of code for developer. This JSTL supports for structural tasks,
common task like conditional and iteration. This tags used for
changing I18N (Internationalization) tags, SQL tags, XML documents
etc. This JSTL also provides a framework for attaching the already
existing custom tags within the Java Standard Tag Library.</p>
</c:if>
<c:if test="${fn:contains(StringType, 'courses')}">
<p>No Given String is not found in the value
<p>
</c:if>
</body>
</html>

출력:

 자바의 JSTL

예 # 9 – c:endsWith 태그가 있는 함수 태그

코드: CEndsWith.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<title>JSTL Tags</title>
</head>
<body>
<c:set var="StringType"
value="We are learning online course from EDUCBA platform" />
<c:if test="${fn:endsWith(StringType, 'platform')}">
<h1 style="color: red">Yes String ends with platfrom.</h1>
<p style="color: fuchsia; border: 1px solid red; font-size: 20px">JSTL
abbreviated as Java Standard Tag Library. Which is further extension
for JSP (Java Server Pages). JSTL reduced the lines of code for
developer. This JSTL supports for structural tasks, common task like
conditional and iteration. This tags used for changing I18N
(Internationalization) tags, SQL tags, XML documents etc. This JSTL
also provides a framework for attaching the already existing custom
tags within the Java Standard Tag Library.</p>
</c:if>
<c:if test="${fn:endsWith(String, 'are')}">
<p>String ends with are.
<p>
</c:if>
</body>
</html>

출력:

자바의 JSTL

위 내용은 자바의 JSTL의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:자바 과도다음 기사:자바 과도