19.05.21 Expression Laguage 사용법 (jsp model 2 2강~3강)
Back-End/JSP 2019. 5. 21. 12:07Expression Laguage = 표현언어라고도 하며 줄여서 "EL" 이라고도 한다.
- 표현식으로 attribute 나 parameter 등을 JSP 파일에서 출력할 용도로 사용하는 언어
- attribute를 출력할 때는 $[애트리뷰트 이름] 으로 출력
- 파라미터는 ${param.이름} 또는 ${paramValue.이름[인덱스]}의 형태로 출력함.
-Expression Laguage 내부에서 사용할 수 있는 연산자 목록-
기호 연산자 |
영문단어 연산자 |
/ |
div |
% |
mod |
&& |
and |
|| |
or |
! |
not |
== |
eq |
!= |
ne |
< |
It (less than) |
> |
gt (greater than) |
<= | le (less or equal) |
>= | ge (greater or equal) |
empty - null 이면 true |
-예제 및 출력 결과-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!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=EUC-KR"> <title>Insert title here</title> </head> <body> <!-- 화면에 출력하는 3가지 방법 --> <% int i = 3; //1. println을 사용 출력하는 방법 //만약 out.println("i = "+i > 4); 처럼 비교문이 들어간 경우엔 출력 불가능 out.println("i = " + i); //2. ${}을 사용해 출력하는 방법, 단, 여기서 i는 위에서 3이라는 값을준 변수 i가 아니라, // request.setAttribute 안에 있는 i에 3을 준다는 의미이다. request.setAttribute("ia", 3); %> <p> <!-- 3. p태그를 이용해 자료를 출력하는 방법 --> <!-- 객체에 담긴 이름은 바로 출력이 불가능 request.setAttribute("ia", 3);에 담긴 ia값은 출력이 불가능 --> <!-- 즉 객체 자체를 호출할 수 없다. --> <!-- 만약 i자리에 "3"과 +4가 들어있다면 문자를 합친 값인 34가 출력이 된다. --> i = <%=i%> </p> <!-- 여기 안에 있는 ia는 request.setAttribute안에 있는 ia를 호출한다. 즉 3이 출력됨, 이런것을 El이라고 한다.--> <!-- 이러한 형식은 request나 session에 자료를 담아두고 사용할때 사용한다.--> <!-- + 같은 연산자도 사용이 가능하다. 객체에 자료를 담아두고 있을때 숫자의 형식이 String 타입이라면 자동으로 integer로 타입이 변환되서 연산을 해준다.--> i = ${ia > 4} </body> </html> | cs |
-예제 및 출력 결과-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <center> <!-- 로그인 페이지 작성 --> <h2>로그인</h2> <form action="ElLoginProc.jsp" method="post"> <table width="300" border="1"> <tr height="40"> <td width="120">아이디</td> <td width="180"><input type="text" name="id"></td> </tr> <tr height="40"> <td width="120">패스워드</td> <td width="180"><input type="password" name="password"> </td> </tr> <tr height="40"> <td align="center" colspan="2"><input type="submit" value="로그인"></td> </tr> </table> </form> </center> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <!-- param을 사용하면 변수의 값을 출력 할수 있다. --> <!-- El 표현식을 사용하는 이유는 파라미터의 데이터를 바로 받아서 사용할때 편하기 때문에 사용한다.--> 당신의 아이디는 ${param.id } 패스워드는 ${param.password } 입니다. </body> </html> | cs |
-예제 및 출력 결과-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <center> <h2>계산기</h2> <form action="ElCul.jsp" method="post"> <table width="450"> <tr height="40"> <td align="center" width="100"><input type="text" name="exp1" value="${ param.exp1 }"></td> <td align="center" width="50"><select name="exp2"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select></td> <td align="center" width="100"><input type="text" name="exp3" value="${ param.exp3 }"></td> <td align="center" width="20">=</td> <td align="center" width="100"> <% //계산기의 계산한 결과값을 출력하는 페이지 //exp2(기호)를 파라미터로 받고 그 파라미터와 equals의 값이 동일하면 el문으로 연산한 값을 출력되게 한다. String exp2 = request.getParameter("exp2"); //exp2가 null값이 되므로 null 처리를 해주어야 한다. if(exp2==null){ exp2 = "+"; } if(exp2.equals("+")){ %> <input type="text" name="exp4" value="${param.exp1 + param.exp3 }"> <% } if(exp2.equals("-")){ %> <input type="text" name="exp4" value="${param.exp1 - param.exp3 }"> <% } if(exp2.equals("*")){ %> <input type="text" name="exp4" value="${param.exp1 * param.exp3 }"> <% } if(exp2.equals("/")){ %> <input type="text" name="exp4" value="${param.exp1 / param.exp3 }"> <% } %> </td> <td align="center" width="100"><input type="submit" value="결과보기"></td> <!-- Proc에서 연산한 값을 다시 이페이지로 가져와서 출력해야된다. --> </tr> </table> </form> </center> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <center> <h2>결과 보기</h2> <form action="ElCul.jsp" method="post"> <% //계산기의 계산한 결과값을 출력하는 페이지 //exp2(기호)를 파라미터로 받고 그 파라미터와 equals의 값이 동일하면 el문으로 연산한 값을 출력되게 한다. String exp2 = request.getParameter("exp2"); if (exp2.equals("+")) { %> 결과는 ${ param.exp1 + param.exp3 } <% } if (exp2.equals("-")) { %> 결과는 ${param.exp1 - param.exp3 } <% } if (exp2.equals("*")) { %> 결과는 ${param.exp1 * param.exp3 } <% } if (exp2.equals("/")) { %> 결과는 ${param.exp1 / param.exp3 } <% } %> </form> </center> </body> </html> | cs |
'Back-End > JSP' 카테고리의 다른 글
19.05.22 서블릿 이해 (0) | 2019.05.22 |
---|---|
19.05.21 jsp MVC model2 programming-JSTL (jsp model 2 4강~5강) (0) | 2019.05.21 |
19.05.21 model 2 방식 이해 (jsp model 2 1강) (0) | 2019.05.21 |
(JSP 인강) jsp web MVC model2 programming (0) | 2019.05.21 |
19.05.20 jsp 쇼핑몰 차량 예약 삭제 (동영상 71강) (1) | 2019.05.20 |