JSP 정리 - 9일차

이원섭·2020년 2월 17일
0

JSP 공부

목록 보기
9/11
post-thumbnail

17. EL

17-1. EL?

EL(Expression Language)란, 표현식 또는 액션 태그를 대신해서 값을 표현하는 언어다.


17-2. EL 연산자

EL안에 자바처럼 연산자를 사용할 수 있다.


17-3. EL 액션태그

EL을 액션태그 대신 사용할 수 있다.

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<jsp:useBean id="member" class="com.javalec.ex.MemberInfo" scope="page" />
<jsp:setProperty name="member" property="name" value="홍길동"/>
<jsp:setProperty name="member" property="id" value="abc"/>
<jsp:setProperty name="member" property="pw" value="123"/>
<!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>
	이름 : <jsp:getProperty name="member" property="name"/><br />
	아이디 : <jsp:getProperty name="member" property="id"/><br />
	비밀번호 : <jsp:getProperty name="member" property="pw"/><br />
	
	<hr />
	
	이름 : ${member.name }<br /> <!-- 위에있는 액션태그보다 코드가 간단하다. -->
	아이디 : ${member.id }<br />
	비밀번호 : ${member.pw }<br />
	
</body>
</html>

17-4. 내장객체

  • pageScope : page객체를 참조하는 객체
  • requestScope : request객체를 참조하는 객체
  • sessionScope : session객체를 참조하는 객체
  • applicationScope : application객체를 참조하는 객체
  • param : 요청 파라미터를 참조하는 객체
  • paramValues : 요청 파라미터(배열)를 참조하는 객체
  • initParam : 초기화 파라미터를 참조하는 객체
  • cookie : cookie객체를 참조하는 객체

ex) ${param.id}, ${pageScope.page_name}, ${initParam.con_name}...


18. JSTL

18-1. JSTL?

JSP의 경우 HTML 태그와 같이 사용되어 전체적인 코드의 가독성이 떨어진다. 그ㅓㄹ한 단점을 보완하고자 만들어진 태그 라이브러리다.


18-2. JSTL 라이브러리


18-3. Core

Core 라이브러리는 기본적인 라이브러리로 출력, 제어문, 반복문 같은 기능이 포함

<%@ taglib uri = http://java.sun.com/jsp/jstl/core prefix="c"%>

출력 태그 : <c:out>

<c:out value="출력값" default="기본값" escapeXml="true or false">
												//default로 두고 사용

변수 설정 태그 : <c:set>

<c:set var="변수명" value="설정값" target="객체" property="값" scope="범위">

변수를 제거하는 태그 : <c:remove>

<c:remove var="변수명" scope="범위">

예외처리 태그 : <c:catch>

<c:catch var="변수명">

제어문(if) 태그 : <c:if>

<c:if test="조건" var="조건 처리 변수명" scope="범위">

제어문(switch) 태그 : <c:choose>

<c:choose>
<c:when test="조건"> 처리내용 </c:when>
<c:otherwise> 처리 내용 </c:otherwise>
</c:choose>

반복문(for) 태그 : <c:forEach>

<c:forEach items="객체명" begin="시작 인덱스" end="끝 인덱스" step="증감식" var="변수명" varStatus="상태변수">

페이지 이동 태그 : <c:redirect>

<c:redirect url="url">

파라미터 전달 태그 : <c:param>

<c:param name="파라미터명" value="값">
profile
개발 공부 가즈아-!

0개의 댓글