EL(Expression Language)
JSTL(Jsp Standard Tag Library)
el.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div>JAVA명령어는 JSTL, EL사용해야한다.</div>
<!-- HTML주석 -->
<%-- JSP주석 --%>
<%-- 1. 데이터, 연산자 --%>
<h3>EL - 1. 출력, 연산자 가능 (직접 데이터 사용가능, 변수(JSTL))</h3>
<ol>
<li>수 출력: ${10}, ${99.99}</li>
<li>문자(문자열) 출력: ${"apple"}, ${'apple'}</li>
<li>연산: ${10+20}, ${10-20}, ${4/5}, ${5%7}</li>
<li>작다: ${2<3}, ${2 lt 3}</li>
<li>크다: ${2>3}, ${2 gt 3}</li>
<li>작거나 같다: ${2.5<=3.7}, ${2 le 3}</li>
<li>크거나 같다: ${2.8>3.3}, ${2 ge 3}</li>
<li>논리연산자: ${"&&, AND, ||, OR, !, NOT"}</li>
<li>빈문자열: ${null}</li>
</ol>
</body>
</html>
MemberInfo.java
package com.java.el;
public class MemberInfo {
private String name;
private String id;
private String pwd;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
@Override
public String toString() {
return "MemberInfo [name=" + name + ", id=" + id + ", pwd=" + pwd + "]";
}
}
memberInfo.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>EL - 2. setMethod, getMethod</h3>
<%-- 객체 선언 MemberInfo member = new MemberInfo() --%>
<jsp:useBean id="member" class="com.java.el.MemberInfo"/>
<%-- setMethod --%>
${member.setName("이영자")}
${member.setId("lee1234")}
${member.setPwd("1234")}
<%-- getMethod / 거의 사용 안함 --%>
<h3>${member.getName()}</h3>
<h3>${member.getId()}</h3>
<h3>${member.getPwd()}</h3>
<br/><br/>
<h3>${member.name}</h3> <%-- get 메소드 호출 --%>
<h3>${member.id}</h3>
<h3>${member.pwd}</h3>
</body>
</html>
objFormView.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="objFormView.jsp" method="post">
<label>이름</label>
<input type="text" name="name"/>
<label>아이디</label>
<input type="text" name="id"/>
<label>비밀번호</label>
<input type="text" name="pwd"/>
<input type="submit" value="전송"/>
<input type="reset" value="취소"/>
</form>
<% // 스플릿 : 자바코드 작성가능
java.util.Date date = new java.util.Date();
// 내장객체로 지원
// pageScope : 현재 페이지에서만 데이터 공유
pageContext.setAttribute("pName", "apple");
// requestScope : 요청시 데이터 공유(form, include, forward)
request.setAttribute("rName", "banana");
// sessionScope : 하나의 웹어플리케이션에서 데이터 공유(cookies, session), 웹 브라우저 한개당
session.setAttribute("sName", "melon");
// applicationScope : 하나의 웹어플리케이션에서 데이터 공유, 웹 서버가 꺼질 때까지
application.setAttribute("aName", "strawberry");
%>
</body>
</html>
objForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- EL 내장객체 - HTTP 요청 파라미터 paramValues -->
<h3>이름: ${param.name}</h3>
<h3>아이디: ${param.id}</h3>
<h3>패스워드: ${param.pwd}</h3>
<br /><br />
<!-- EL 내장객체 - JSP 저장객체(Scope) 읽기 -->
<ul>
<li>${pageScope.pName}</li> <%-- 결과안나옴 --%>
<li>${requestScope.rName}</li> <%-- 결과안나옴 --%>
<li>${sessionScope.sName}</li>
<li>${applicationScope.aName}</li>
</ul>
</body>
</html>
페이지를 다 끄고 다시 실행시키면 strawberry만 살아 있는다.
'Coding > JSP' 카테고리의 다른 글
[MVC/DB연동] 로그인 페이지 (로그아웃, 회원수정, 회원탈퇴 기능) (2) (0) | 2022.04.08 |
---|---|
JSTL(JSP Standard Tag Library) 다운로드 / c:set, c:remove (0) | 2022.04.04 |
[Servlet] Cookie(쿠키)/ Session(세션) (0) | 2022.04.04 |
[Servlet] Servlet 객체 범위 (0) | 2022.04.04 |
[Servlet] Servlet(서블릿) (1) (0) | 2022.04.04 |