1) EL(Expression Language)
νν μΈμ΄μ κΈ°λ³Έ κ°μ²΄ μ¬μ© μ
νν μΈμ΄μ λ°μ΄ν° νμ
-
λΆλ¦¬μΈ νμ - trueμ false
-
μ μνμ - 0~9λ‘ μ΄λ£¨μ΄μ§ μ μ κ° μμμ κ²½μ° '-'κ° λΆμ
-
μ€μνμ - 0~9λ‘ μ΄λ£¨μ΄μ Έ μμΌλ©°, μμμ ('.')μ μ¬μ©ν μ μκ³ , 3.24e3κ³Ό κ°μ΄ μ§μνμΌλ‘ νν κ°λ₯νλ€.
-
λ¬Έμμ΄ νμ - λ°μ΄ν( ' λλ" )λ‘ λλ¬μΌ λ¬Έμμ΄. λ§μ½ μμ λ°μ΄ν(')λ₯Ό μ¬μ©ν΄μ ννν κ²½μ° κ°μ ν¬ν¨λ μμ λ°μ΄νλ \' μ κ°μ΄ \ κΈ°νΈμ ν¨κ» μ¬μ©ν΄μΌ νλ€.
-
\ κΈ°νΈ μ체λ \\ λ‘ νμνλ€.
-
λ νμ - null
κ°μ²΄ μ κ·Ό κ·μΉ
-
νν 1μ΄λ νν 2κ° nullμ΄λ©΄ nullμ λ°ννλ€.
-
νν1μ΄ MapμΌ κ²½μ° νν2λ₯Ό keyλ‘ν κ°μ λ°ννλ€.
-
νν1μ΄ Listλ λ°°μ΄μ΄λ©΄ νν2κ° μ μμΌ κ²½μ° ν΄λΉ μ μ λ²μ§Έ indexμ ν΄λΉνλ κ°μ λ°ννλ€. λ§μ½ μ μκ° μλ κ²½μ°μλ μ€λ₯κ° λ°μνλ€.
-
νν1μ΄ κ°μ²΄μΌ κ²½μ°λ νν2μ ν΄λΉνλ getterλ©μλμ ν΄λΉνλ λ©μλλ₯Ό νΈμΆν κ²°κ³Όλ₯Ό λ°ννλ€.
νν μΈμ΄μ μμΉ μ°μ°μ
-
+ : λ§μ
-
- : λΊμ
-
* : κ³±μ
-
/ λλ div : λλμ
-
% λλ mod : λλ¨Έμ§
-
μ«μκ° μλ κ°μ²΄μ μμΉ μ°μ°μλ₯Ό μ¬μ©ν κ²½μ° κ°μ²΄λ₯Ό μ«μ κ°μΌλ‘ λ³ν ν μ°μ°μλ₯Ό μν : ${"10"+1} → ${10+1}
-
μ«μλ‘ λ³νν μ μλ κ°μ²΄μ μμΉ μ°μ°μλ₯Ό ν¨κ» μ¬μ©νλ©΄ μλ¬λ₯Ό λ°μ : ${"μ΄"+1} → μλ¬
-
μμΉ μ°μ°μμμ μ¬μ©λλ κ°μ²΄κ° nullμ΄λ©΄ 0μΌλ‘ μ²λ¦¬ : ${null + 1} → ${0+1}
λΉκ΅ μ°μ°μ
-
== λλ eq
-
!= λλ ne
-
< λλ lt
-
> λλ gt
-
<= λλ le
-
>= λλ ge
-
λ¬Έμμ΄ λΉκ΅: ${str == 'κ°'} str.compareTo("κ°") == 0 κ³Ό λμΌ
λ Όλ¦¬ μ°μ°μ
-
&& λλ and
-
|| λλ or
-
! λλ not
empty μ°μ°μ, λΉκ΅μ ν μ°μ°μ
μ°μ°μ μ°μ μμ
-
[] .
-
()
-
- (λ¨μΌ) not ! empty
-
* / div % mod
-
+ -
-
< > <= >= lt gt le ge
-
== != eq ne
-
&& and
-
|| or
-
? :
νν μΈμ΄ λΉνμ±ν : JSPμ λͺ μνκΈ°
default : false → EL μΈμ
-
<%@ page isELIgnored = "true" %>
el01.jsp Scopeλ³ νν μΈμ΄μ μ¬μ©
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
pageContext.setAttribute("p1", "page scope value");
request.setAttribute("r1", "request scope value");
session.setAttribute("s1", "session scope value");
application.setAttribute("a1", "application scope value");
%>
<!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">
<title>Insert title here</title>
</head>
<body>
pageContext.getAttribute("p1") : ${pageScope.p1 }<br>
request.getAttribute("r1") : ${requestScope.r1 }<br>
session.getAttribute("s1") : ${sessionScope.s1 }<br>
application.getAttribute("a1") : ${applicationScope.a1 }<br>
<br><br>
λ³μκ° κ²ΉμΉμ§ μμΌλκΉ μ΄λ κ² μ¬μ© κ°λ₯! _ νμ§λ§ νμ€ν μ°λκ² λ ν¨μ¨μ
pageContext.getAttribute("p1") : ${p1 }<br>
request.getAttribute("r1") : ${r1 }<br>
session.getAttribute("s1") : ${s1 }<br>
application.getAttribute("a1") : ${a1 }<br>
</body>
</html>
el02.jsp νν μΈμ΄μ μ°μ°
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setAttribute("k", 10);
request.setAttribute("m", true);
%>
<!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">
<title>Insert title here</title>
</head>
<body>
k : ${k } <br>
k + 5 : ${ k + 5 } <br>
k - 5 : ${ k - 5 } <br>
k * 5 : ${ k * 5 } <br>
k / 5 : ${ k div 5 } <br>
k : ${k }<br>
m : ${m }<br>
k > 5 : ${ k > 5 } <br>
k < 5 : ${ k < 5 } <br>
k <= 10 : ${ k <= 10} <br>
k >= 10 : ${ k >= 10 } <br>
m : ${ m } <br>
!m : ${ !m } <br>
</body>
</html>
* EL λ¬Έλ² μ¬μ©νμ§ μκ³ λ¬Έμμ΄ κ·Έλλ‘ νμν λ
<%@ page isELIgnored = "true" %>
2) JSTL(JSP Standard Tag Library)
JSTLμ΄λ?
- JSTL(JSP Standard Tag Library)μ JSP νμ΄μ§μμ 쑰건문 μ²λ¦¬, λ°λ³΅λ¬Έ μ²λ¦¬ λ±μ html tagννλ‘ μμ±ν μ μκ² λμμ€λλ€.
JSTLμ μ¬μ©νλ €λ©΄?
- http://tomcat.apache.org/download-taglibs.cgi
- μμ μ¬μ΄νΈμμ 3κ°μ§ jarνμΌμ λ€μ΄λ‘λ ν ν WEB-INF/lib/ ν΄λμ 볡μ¬λ₯Ό νλ€.
JSTLμ΄ μ 곡νλ νκ·Έμ μ’ λ₯
μ½μ΄ νκ·Έ
μ½μ΄ νκ·Έ: λ³μ μ§μ νκ·Έ - set, remove
jstl01.jsp set, removeμ νμ©
<%@ 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="kang"/>
<!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">
<title>Insert title here</title>
</head>
<body>
μ± : ${value1} <br>
<c:remove var="value1" scope="request"/>
μ± : ${value1 }
</body>
</html>
μ½μ΄νκ·Έ: λ³μ μ§μ νκ·Έ - νλ‘νΌν°, 맡μ μ²λ¦¬
λ³μ μ§μ νκ·Έ
μ½μ΄ νκ·Έ: νλ¦μ μ΄ νκ·Έ
jstl02.jsp ifμ νμ©
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
request.setAttribute("n", 10);
%>
<!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">
<title>Insert title here</title>
</head>
<body>
<c:if test="${n == 0}">
nμ κ³Ό 0κ³Ό κ°μ΅λλ€.
</c:if>
<c:if test="${n == 10}">
nμ κ³Ό 10κ³Ό κ°μ΅λλ€.
</c:if>
</body>
</html>
μ½μ΄ νκ·Έ: νλ¦μ μ΄ νκ·Έ - choose
jstl03.jsp switchμ νμ©
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*" %>
<%
request.setAttribute("score", 83);
%>
<!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">
<title>Insert title here</title>
</head>
<body>
<c:choose>
<c:when test="${score >=90 }">
Aνμ μ
λλ€.
</c:when>
<c:when test="${score >=80 }">
Bνμ μ
λλ€.
</c:when>
<c:when test="${score >=70 }">
Cνμ μ
λλ€.
</c:when>
<c:when test="${score >=60 }">
Dνμ μ
λλ€.
</c:when>
<c:otherwise>
Fνμ μ
λλ€.
</c:otherwise>
</c:choose>
</body>
</html>
μ½μ΄ νκ·Έ: νλ¦μ μ΄ νκ·Έ - forEach
jstl04.jsp forEachμ νμ©
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*" %>
<%
List<String> list = new ArrayList<>();
list.add("hello");
list.add("world");
list.add("!!!");
request.setAttribute("list", list);
%>
<!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">
<title>Insert title here</title>
</head>
<body>
<c:forEach items="${list}" var="item">
${item } <br>
</c:forEach>
</body>
</html>
μ½μ΄ νκ·Έ: νλ¦μ μ΄νκ·Έ - import
jstlValue.jsp importμ νμ©
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Kang kyungmi
jstl05.jsp importμ νμ©
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*" %>
<c:import url="http://localhost:8080/webapp/jstlValue.jsp" var="urlValue" scope="request"></c:import>
<!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">
<title>Insert title here</title>
</head>
<body>
μ½μ΄λ€μΈ κ° : ${urlValue}
</body>
</html>
μ½μ΄ νκ·Έ: νλ¦μ μ΄νκ·Έ - redirect
jtl06.jsp redirectμ νμ©
<%@ 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"></c:redirect>
jstlRedirectPage.jsp redirectμ νμ©
<%@ 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">
<title>Insert title here</title>
</head>
<body>
<h1> redirectλ νλ©΄μ
λλ€.</h1>
</body>
</html>
μ½μ΄ νκ·Έ: κΈ°ννκ·Έ - out
jstl07.jsp outμ νμ©
<%@ 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">
<title>Insert title here</title>
</head>
<body>
<c:set var="t" value="<script type='text/javascript'>alert(1);</script>" />
${t}
<c:out value="${t}" escapeXml="true" />
<c:out value="${t}" escapeXml="false" />
</body>
</html>
'Spring > Boost Course Web' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
3.3 Spring JDBC (0) | 2020.11.19 |
---|---|
3.2 Spring Test (0) | 2020.11.19 |
3.1 Spring Core (0) | 2020.11.19 |
2.5 Scope (0) | 2020.11.19 |
2.4 JSP (0) | 2020.11.19 |
2.3 Servlet (0) | 2020.11.19 |