본문 바로가기

Web/기타

[JSTL] JSTL - set, remove

set 

- 변수 설정. 지정한 영역에 변수를 생성함. 

1
2
3
4
5
<c:set var="varName" scope="session" value="someValue" />
 
<c:set var="varName" scope="request">
some Value
</c:set>
cs

위의 코드를 표현식으로 바꾸면 다음과 같다.
1
2
3
<%
request.setAttribute("var", "someValue");
%>
cs


var - EL에서 사용될 변수명

scope - 변수 값이 저장될 영역(page, request, session, application)

value - 변수 값



remove 

- 변수 제거.

1
<c:remove var="varName" scope="request"/>
cs


- 실습

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<c:set var="value1" scope="request" value="hh_lin" />
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        Name : ${value1} <br>
 
        <c:remove var="value1" scope="request" />
 
        Name : ${value1} <br>
    </body>
</html>
cs




property, Map의 처리

아래와 같은 JSTL이 실행될 때

some 객체가 자바빈일 경우 some.setPropertyName(anyValue); 으로

some 객체가 Mape일 경우 some.put(propertyName, anyValue); 으로 실행되게 된다.

1
<c:set target="${some}" property="propertyName" value="anyValue" />
cs

target - <c:set>으로 지정한 변수 객체

property - 프로퍼티 이름

value - 새로 지정할 프로퍼티 값








참고자료

https://www.edwith.org

'Web > 기타' 카테고리의 다른 글

[JSTL] JSTL - redirect, out  (0) 2018.12.27
[JSTL] JSTL - if, choose, forEach, import  (0) 2018.12.27
[JSTL] JSTL 개요  (0) 2018.12.27
[EL] EL(2)  (0) 2018.12.26
[EL] EL(1)  (0) 2018.12.26