Web/기타
[JSTL] JSTL - redirect, out
hh_lin
2018. 12. 27. 17:56
redirect
지정한 페이지로 리다이렉트한다. response.sendRedirect()와 비슷하다.
1 2 3 | <c:redirect url="리다이렉트할 URL"> <c:param name="파라미터 이름" value="파라미터 값"/> </c:redirect> | cs |
url - 리다이렉트할 URL
<c:param> - 리다이렉트할 페이지에 전달할 파라미터 지정
- jstl.jsp
1 2 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <c:redirect url="jstlRedirectPage.jsp" /> | cs |
- jstlRedirectPage.jsp
1 2 3 4 5 6 7 8 9 10 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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> <h1> redirect된 화면입니다.</h1> </body> </html> | cs |
out
JspWriter에 데이터를 출력한다.
1 | <c:out value="value" escapeXml="{true|false}" default="defaultValue" /> | cs |
value - JspWriter에 출력할 값을 나타낸다. 일반적으로 value 속성의 값은 String과 같은 문자열이다.
만약 value의 값이 java.io.Reader의 한 종류라면 out태그는 Reader로부터 데이터를 읽어와 JspWriter에 값을 출력한다.
escapeXml - 이 속성의 값이 true일 경우 아래 표와 같이 문자를 변경한다. 생략할 수 있으며, 생략할 경우 기본값은 true이다.
default - value 속성에서 지정한 값이 존재하지 않을 때 사용될 값을 지정한다.
문자 |
변환된 형태 |
< |
< |
> |
> |
& |
& |
' |
' |
" |
" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <!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> <c:set var="t" value="<script type='text/javascript'>alert(1);</script>" /> ${t} <c:out value="${t}" escapeXml="false" /> </body> </html> | cs |
escapeXml 속성을 true로 바꾸면 다음과 같이 JavaScript가 실행되는 것이 아니라 문자열로 출력되는 것을 볼 수 있다.
참고자료