2019.02.18 EL(Expression Langauage)

2019. 2. 18. 11:31JSP

 EL(Expression Langauage) 

:JSP 스크립트 태그 (<%=%>)를 대신하여 JSP값들을 좀더 편리하게 

출력하기 위해 제공되는 언어                                    



#1 HTML의 값을 param으로 받아오기


①loginForm.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Form</title>
</head>
<body>
    <form action="login.jsp">
        <input type ="text" name="id"><br>
        <input type ="text" name ="id"><br>
        <input type ="password" name="pw"><br>
        <input type="submit" value ="전송">
    </form>
</body>
</html>
cs


②login.jsp

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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <!-- id값이 중복일 경우 paramValues로 배열로 만들어서 받아온다 -->
    ${paramValues.id[0]}<br>
    ${paramValues.id[1]}<br>
    ${param.pw}
</body>
</html>
cs



③ 출력



#2 EL의 연산자사용


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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>EL</title>
</head>
<body>
    <!-- El의 연산자 사용 -->
    <h3>\${5+7} = ${5+7}</h3>
    <h3>\${10==9} = ${10==9}</h3>
    <h3>\${5+3==8 ? 8: 10} = ${5+3==8 ? 8: 10}</h3>
</body>
</html>
cs