๐ป
JSP ํ๋ก๊ทธ๋๋ฐ - EL, JSTL ๋ณธ๋ฌธ
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๋ง ์ด์ ์๋๋ค.
๋ฐ์ํ
'KITRI > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JSP ํ๋ก๊ทธ๋๋ฐ - [JSTL] core (0) | 2020.06.29 |
---|---|
JSP ํ๋ก๊ทธ๋๋ฐ - JSTL(JSP Standard Tag Library) ๋ค์ด๋ก๋ / c:set, c:remove (0) | 2020.06.10 |
JSP ํ๋ก๊ทธ๋๋ฐ - [Servlet] Cookie(์ฟ ํค)/ Session(์ธ์ ) (0) | 2020.06.09 |
JSP ํ๋ก๊ทธ๋๋ฐ - [Servlet] Servlet ๊ฐ์ฒด ๋ฒ์ (0) | 2020.06.09 |
JSP ํ๋ก๊ทธ๋๋ฐ - [Servlet] Servlet(์๋ธ๋ฆฟ) (2) (0) | 2020.06.08 |
Comments