[Thymeleaf] What - th:text, th:utext 차이점.

하쮸·2025년 11월 3일

Error, Why, What, How

목록 보기
50/63

1. 차이점.

	@GetMapping("/thymeleaf")
	public String thymeleaf(Model model) {
		model.addAttribute("message", "<h1>th:text</h1>");
		return "thymeleaf_test";
	}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p th:text="${message}"></p>
    <p th:utext="${message}"></p>
</body>
</html>

  • th:text
    • HTML 이스케이프 적용.
    • HTML 태그가 문자 그대로 출력됨. (보안 안전)
    • XSS(교차 사이트 스크립팅) 공격으로 안전.
  • th:utext
    • HTML 이스케이프 미적용 (unescaped)
    • HTML 태그가 렌더링됨. (주의 필요)
    • XSS(교차 사이트 스크립팅) 공격 위험이 있음.
profile
Every cloud has a silver lining.

0개의 댓글