Jam's story

[JSP] EL 본문

JSP

[JSP] EL

애플쩀 2022. 6. 22. 16:52
EL
  p250 Chapter 11 표현 언어(Expression Language == EL)
  -표현식을 간결하고 편리하게 사용하기 위한 또 다른 형태의 스크립트 언어
  -JSTL 1.0 소개
  - 톰캣 8.5 + JSP 2.3, EL
  -[EL 기능]
  1)쿠키, JSP 기본객체 사용
  2)람다식 사용
  3) 수치, 관계, 논리 연산자 사용( empty, not == eq, != ne 등등 )
  4) JSP 4가지 영역(scope) 사용
  5) 자바 클래스의 메서드 호출 가능
  정적(static) 메서드 호출 가능
  등등
   
  -EL 사용 선언 형식
  ${ EL 표현 }
  #{ EL 표현 } --이거는 많이 안쓰여서 기억 안해도 된다.
   
   
  --%>
  앞으로의 일정 
  1.EL
  2.JSTL
  3.MVC 패턴 - 방명록 , 답변형 게시판
  4. 필터
  --JSP
  5. jquery Ajax
  6. JSON
  7. 구글 맵 OPEN API
  8. 차트
  9. 파일업로드+ 게시판
  10. 우편번호 OPEN API
${ true }<br>
${ -10 }<br>
${ 3.14 }<br>
${ "홍\"길동"}<br>
${ '홍\'길동'}<br>
${null }<br>

1.수치 연산자 + - * / %
div mod

${3 + 5}<br>
${3 - 5}<br>
${3 * 5}<br>
${3 / 5} ==  ${ 3 div 5 }<br>
${3 % 5} == ${ 3 mod 5  }<br>

 

2. 비교 연산자
 == eq
 != ne
 < lt
 > gt
 <= le
 >= ge

${ 5==3  } == ${ 5 eq 3    }<br>
${ 5!= 3 } == ${ 5 ne 3    }<br>
${ 5 < 3 } == ${ 5 lt 3    }<br>
${ 5 > 3 } == ${ 5 gt 3    }<br>
${ 5<=3 } == ${  5 le 3   }<br>
${ 5>=3 } == ${  5 ge 3   }<br>

 

 

  &&   and
  ||   or
  !    not

${true && true } == ${ true and true }<br>
${true || true } == ${ true or true }<br>
${!true } == ${ not true }<br>

 

값 null         true
값 ""  true
배열길이 0      true
빈 Map          true
빈 Collection    true

	위의 경우 외에 empty 연산자의 결과는 false 리턴한다.

</pre>

${empty "" }<br>
${empty null }<br>
X ${empty 0 }<br>

  

<!-- ${A; B}  B값만 출력된다 C는 안됨-->
${1+1 ; 10+10; }

 

<%
request.setAttribute("title", "jsp");
%>

${"제목:"+=title }<br>

 

<!-- 할당대입연산자 
var1에 값을 할당하고 var1출력하겠다.  -->


${var1=10}

 

00,000으로 출력하기 

<%
long price=22345;
request.setAttribute("price",price);
%>
price=<%=price %><br>
price=${price }
단가를 세 자리마다 콤마를 찍어서 출력...
price=<%=String.format("%,d",price) %><br>
<%
DecimalFormat df=new DecimalFormat("###,###");
String str=df.format(price);
%>
price=<%=str %><br>

 

1.pageContext     == page
2. pageScope  ==pageContext.setAttribute("deptno",10)
   requestScope ==request.setAttribute("empno",7369)
   sessionScope ==session.setAttribute("ename","SMITH")
   applictionScope

***3.param    ==requestgetParameter("age")
   param.age
4. ?name=kenik&name=hong&name=admin
paramValues ==  request.getParameterValues("name");
paramValues.name
5. header    ==    requset.getHeader()
6. headerValues ==  request.getHeaderValues();
7. cookie     == request.getCookies()
Map 객체 = key,value
쿠키이름, 쿠키 객체(Cookie)
8.initParam == application.getInitParameter()

 

 

<h3>ex09_04_02.jsp</h3>

요청 URI:<%= request.getRequestURI() %><br>
요청 URL:<%= request.getRequestURL() %><br>

<hr />
요청 URI : ${ pageContext.request.requestURI } <br>
요청 URL : ${ pageContext.request.requestURL } <br>


<!-- 그냥 request 객체는 없다. 그래서 기본 객체인 pageContext를 사용해서 request객체를 불러온다.  -->





<hr />
<%
	request.setAttribute("name", "홍킬동");
	session.setAttribute("age", 20);
	
%>
name = ${requestScope.name }<br>
age = ${requestScope.age }<br>
<hr>
내부목적으로 모든 영역(scope) 다 뒤져서 가져온다.

name = ${name }<br>
name = ${age }<br>

<hr>

<%
	String color = request.getParameter("color");
%>
color = <%= color %><br>
color = ${ param.color }<br>

<hr>

<a href="ex09_04_03.jsp?color=red&color=black&color=blue">ex09_04_03.jsp</a>

 

<pre>
?color=red&color=black&color=blue
</pre>

<%
	/* 쿼리스트링에서 변수가 여러개가 넘어 오므로 배열로 선언해 준다. */
	String[] colors = request.getParameterValues("color");
	for(int i =0; i<colors.length;i++){
%>
<li>color:<%=colors[i] %></li>	
<%		
}
%>

 

 

 

8. EL에서 사용할 기본 객체                    JSP 기본 객체  
      1) pageContext                       /        pageContext
      2) key/value [Map 객체]
          pageScope
          requestScope                     /        request .setAttribute()
          sessionScope                     /        session
          applicationScope                /        application
          
      3) param                              /       request .getParameter()
      4) paramValues                     /       request .getParameterValues()
      5) cookie 
      6) initParam                          /       application .getInitParameter()
      7) header                             /       request .getHeader()
      8) headerValues                    /      request .getHeaderValues()

 

'JSP' 카테고리의 다른 글

[JSP] JSTL  (0) 2022.06.23
[JSP] EL을 사용해서 쿠키를 읽고 쓰기  (0) 2022.06.23
[JSP] 세션  (0) 2022.06.22
[JSP] 커넥션풀  (0) 2022.06.22
[JSP] 로그인 화면  (0) 2022.06.22
Comments