자바코드를 사용하지 않고 출력,추출
변수, 숫자, 문자열, 수식, boolean, null을 사용할 수 있음
EL 사용을 위해 isElgnored="false"로 지정하면 EL 구문이 문자열로 인식됨.
pageScope : page 영역에 바인딩된 속성을 참조하는 내장객체
${내장객체.속성이름}
request.setAttribute("nation","korea")
/* request 내장 객체에 바인딩 되어 있는 nation 속성 참조 */
${requestScope.nation}
/* 내장 객체 이름을 생략하고 속성 이름만 출력*/
${nation}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
request.setAttribute("city", "seoul");
session.setAttribute("nation", "korea");
application.setAttribute("nation", "france");
%>
<jsp:forward page = "scopeTo.jsp"/>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
out.println(request.getAttribute("city"));
out.println("<br>");
%>
1. ${city} <br>
<%-- session이 application 영역보다 우선순위가 높기 때문에 korea 출력 --%>
2. ${nation} <br>
<%-- applicationScope 내장객체 이름을 지정했으므로 france --%>
3. ${applicationScope.nation}
<%--
출력 :
seoul
1. seoul
2. korea
3. france
--%>
클라이언트에서 전달된 파라미터의 값을 추출해 출력
${param.파라미터 이름}
${paramValues.파라미터 이름[index]}
//지정 헤더 값 추출 및 출력
${header.헤더이름}
${header.["헤더이름"]}
헤더 이름에 '_'기호가 아닌 다른 특수문자가 있다면 headerValues 사용
${header.헤더이름[index]}
// 특수문자, 기호가 있을 경우 밑에 방법 사용
${header.["헤더이름"][index]}
${cookie.쿠키이름.value}
${cookie.쿠키이름.["value"]}
// '_' 가 아닌 특수문자가 있다면 아래 두 방법을 사용
${cookie["쿠키이름"].value}
${cookie["쿠키이름"].["value"]}
<%-- 쿠키 생성 --%>
Cookie cookie1 = new Cookie("userName", "hong");
response.addCookie(cookie1);
현재 수행중인 JSP문서를 참조할 수 있는 pageContext 내장 객체 제공
${빈즈이름.멤버변수이름}
package chapter10;
public class ExpBean {
private String userId;
private String userName;
private String userMail;
/* Getter Setter */
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setusername(String userName) {
this.userName = userName;
}
public String getUserMail() {
return userMail;
}
public void setUserMail(String userMail) {
this.userMail = userMail;
}
}
<form name="myform" method="post" action="expBeanTo.jsp">
아이디: <input type="text" name="userId" size=20><br>
이 름: <input type="text" name="userName" size=20><br>
메 일: <input type="text" name="userMail" size=30><br>
<input type="submit" value="저장" ><br>
</form>
<%@ page import="chapter10.*" %>
<% request.setCharacterEncoding("utf-8"); %>
<jsp:useBean id="expBean" class="chapter10.ExpBean" scope="request"/>
<jsp:setProperty property="*" name="expBean"/>
<b> Getter를 이용한 추출 </b> <br>
아이디 : <%=expBean.getUserId() %><br>
이름 : <%=expBean.getUserName()%><br>
메일 : <%=expBean.getUserMail()%><br>
<b> 액션 태그를 이용한 추출</b> <br>
아이디 : <jsp:getProperty property="userId" name="expBean"/><br>
이름 : <jsp:getProperty property="userName" name="expBean"/><br>
메일 : <jsp:getProperty property="userMail" name="expBean"/><br>
<b>EL을 이용한 추출</b> <br>
아이디 : ${expBean.userId} <br>
이름 : ${expBean.userName} <br>
메일 : ${expBean.userMail} <br>