노력과 삽질 퇴적물

JSP: 표현언어(el) 본문

📂기초 및 세팅 note/언어. 스크립트 계열

JSP: 표현언어(el)

MTG 2012. 9. 5. 09:43






0. 기본개념

JSP 2.0부터 지원

JSP페이지에서 자바코드를 없애기 위한 방법


값이 없으면 null을 출력X, 기본적으로 자바문법 사용


*.jsp문서에서 정삭적으로 작동한다.






1. EL 변수 출력법

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>el01.jsp</title>

</head>


<body>

<h3> 간단한 표현 언어(EL) 예제입니다.</h3>

<table border="1">

<tr> <th>표현값</th>

<th>값</th>

</tr>

<tr> <td>사칙연산</td>  

<td>${2+5}, ${2-5}, ${2*5}, ${2/5}</td>

</tr>

<tr> <td>나머지</td>

<td>${5 mod 7}</td>

</tr>

<tr> <td>보다작다</td>

<td>${2<3}</td>

</tr>

<tr> <td>크다, 작다</td>

<td>${2 gt 3}, ${2 lt 3}</td>

</tr>

<tr> <td>크거나 같다, 작거나 같다</td>

<td>${3.1 ge 3.2}, ${3.1 le 3.2}</td>

</tr>

<tr>

<td>브라켓 연산자 [ip와 port번호]</td>

<td>${header["host"]}, ${header['host']}, ${header.host}  </td>

</tr>

<tr> <td>브라켓 연산자[웹 브라우저 종류]</td>

<td>${header["user-agent"]}, ${header['user-agent']}, 

${header.user-agent}</td>

</tr>

</table>


</body>

</html>






2. 파리미터 전달과 처리

el02_form.jsp

<%@ 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>el02_form.jsp</title>

</head>

<body>

<h3>표현언어의 파라미터 값 처리</h3>

<form action="el02_View.jsp" method="post">

이름 : <input type="text" name="name"/><br><br>

선택 : <input type="checkbox" name="lang" value="JAVA"/>JAVA<br>

선택 : <input type="checkbox" name="lang" value="JSP"/>JSP<br>

선택 : <input type="checkbox" name="lang" value="오라클"/>오라클<br>

선택 : <input type="checkbox" name="lang" value="C++"/>C++<br>

<input type="submit" value="OK"/>

<input type="reset" value="cancel"/>

</form>

</body>

</html>

el02_View.jsp

<%@ 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">

<%

request.setCharacterEncoding("utf-8");

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>el02_View.jsp</title>

</head>

<body>

이름은 ${param.name}입니다.<br>

과일은 ${paramValues.lang[0]}  ${paramValues.lang[1]}

${paramValues.lang[2]} ${paramValues.lang[3]}입니다.

</body>

</html>






3. 표현언어에서 매소드

el03_form.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib prefix="el" uri="/WEB-INF/tlds/el-functions.tld" %>

<!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>el03_form.jsp</title>

</head>

<body>

<h3>표현언어에서 매소드 사용하기</h3>

<form action="el03_View.jsp" method="post">

x : <input type="text" name ="x"><br><br>

y : <input type="text" name ="y"><br><br>

<input type="submit" value="덧셈연산">

</form>

</body>

</html>

 el03_View.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib prefix="el" uri="/WEB-INF/tlds/el-functions.tld" %>

<!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>el03_View.jsp</title>

</head>

<body>

${param.x }, ${param.y }입니다.

${el:add( param.x, param.y )}입니다.

</body>

</html>




el03-2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib prefix="el" uri="/WEB-INF/tlds/el-functions.tld" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<%

java.util.Date today = new java.util.Date();

request.setAttribute("today", today);

%>


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>el03-2.jsp</title>

</head>

<body>

오늘은 ${el:getFormat(today) }

</body>

</html>

'📂기초 및 세팅 note > 언어. 스크립트 계열' 카테고리의 다른 글

파이썬: 기초정리 (1)  (2) 2013.05.07
JSP: JSP 기초(2)  (0) 2012.09.13
JSP: JSP 기초(1)  (0) 2012.08.02
HTML: html태그 기초  (0) 2012.08.01
프로세싱(processing)  (0) 2011.12.12