728x90
반응형

1
<c:set/> : 변수 선언


<!-- coreTags1.jsp EL 은 표현 JSTL 은 태그화 -->
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String str1 = "JSP의 JSTL";
String str2 = null;
%>
<!-- 4개의저장소 변수를 선언 -->
<c:set var="str3" value="JSPstudy" scope="page"/>
<c:set var="str4" value="JSTL" scope="session"/>
<!-- 변수의 출력 -->
-<c:out value="<%= str1 %>" default="기본출력값"/><br>
-<c:out value="<%= str2 %>" default="기본출력값"/><br> <!-- 값이 null 이면 default값 출력 -->
-<c:out value="${str3}" default="기본출력값"/><br>
<!-- 변수를 저장소에서 삭제 -->
<c:remove var="str4"/>
<% String str5 = (String)pageContext.getAttribute("str3"); %>
-<%= str5 %>
2

<c:choose>
<c:when>


<!-- coreTags2.jsp -->
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String id = request.getParameter("id");
%>
<!-- if태그 -->
<c:if test="${param.id != null}" >
<b>${param.id}</b>
</c:if>
<c:if test="${param.id == null}" >
<b>Guest</b>
</c:if>
<c:choose>
<c:when test="${param.color == 'yellow'}">
<c:set var="c" value="노란색"></c:set>
</c:when>
<c:when test="${param.color == 'blue'}">
<c:set var="c" value="파란색"></c:set>
</c:when>
<c:when test="${param.color == 'orange'}">
<c:set var="c" value="오렌지색"></c:set>
</c:when>
<c:when test="${param.color == 'pink'}">
<c:set var="c" value="핑크색"></c:set>
</c:when>
<c:when test="${param.color == 'black'}">
<c:set var="c" value="검은색"></c:set>
</c:when>
</c:choose>
님이 좋아하는 색상은 <font color="${param.color }">${c}</font><br>
msg : ${param.msg}
3


<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String str1[] = {"Java","JSP","Android","Spring"};
String str2 = "블랙핑크;AOA,트와이스;레드벨벳";
%>
<c:set var="arr" value="<%= str1 %>" />
<c:forEach var="i" items="${arr}" begin="0" step="1" end="3">
${i}<br>
</c:forEach>
<hr align="left" width="250">
<c:set var="s" value="<%= str2 %>"/>
<c:forTokens var="st" items="${s}" delims=",;">
<b>${st}</b>
</c:forTokens>
4


5

<!-- coreTags2.jsp -->
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:redirect url="https://www.tesla.com/ko_kr"/>
6


<!-- coreTags2.jsp -->
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:catch var="ex">
<%
int arr[] = {1,2,3};
int sum = arr[0] + arr [3];
%>
</c:catch>
${ex}
728x90
반응형
'Spring > JSTL' 카테고리의 다른 글
| JSTL SessionScope (0) | 2021.08.04 |
|---|---|
| JSP로 이메일 보내기 ㅇㅇ (0) | 2021.08.03 |
| JSTL fmtTags (0) | 2021.07.27 |
| JSTL EL (0) | 2021.07.26 |
| JSP 액션태그 (0) | 2021.06.01 |
| JSP 디렉티브 태그 (0) | 2021.06.01 |