package board.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import board.dto.BoardDTO;
public class BoardDAO {
private Connection con;
private PreparedStatement pstmt;
private ResultSet res;
private DataSource ds;
public BoardDAO() {
try {
// InitalContect 객체 생성해서 설정된 정보 가져오기 : JNDI
Context context = new InitialContext();
// Context 클래스의 lookup() 메서드는 'java:comp/env/jdbc/oracle' 을 가지고 DataSource 객체를 구합니다
// - lookup() 메서드를 사용해서 naming 서비스에서 자원을 찾습니다
// - JNDI 의 이름은 'java:comp/env/' 에 등록되어 있습니다
ds = (DataSource)context.lookup("java:comp/env/jdbc/oracle");
} catch (Exception e) {
e.printStackTrace();
}
}
// 글쓰기
public int write(BoardDTO dto) {
int su = 0;
try {
String sql = "INSERT INTO board VALUES(board_seq.NEXTVAL,?,?,?,?,0,SYSDATE)";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
String[] arr = {dto.getId(), dto.getName(), dto.getSubject(), dto.getContent()};
for (int i = 1; i <= 4; i++) {
pstmt.setString(i, arr[i - 1]);
}
// pstmt.setString(1, dto.getId());
// pstmt.setString(2, dto.getName());
// pstmt.setString(3, dto.getSubject());
// pstmt.setString(4, dto.getContent());
su = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (pstmt != null)
pstmt.close();
if (con != null)
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return su;
}
// db 통로
public void streamClose(ResultSet res, PreparedStatement pstmt, Connection con) {
try {
if (res != null)
res.close();
if (pstmt != null)
pstmt.close();
if (con != null)
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}// streamClase end
public void streamClose(PreparedStatement pstmt, Connection con) {
try {
if (pstmt != null)
pstmt.close();
if (con != null)
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}// streamClase end
public ArrayList<BoardDTO> boardList(int startNum, int lastNum) {
ArrayList<BoardDTO> list = new ArrayList<>();
BoardDTO dto = null;
try {
String sql ="SELECT seq,id,name,subject,content,hit,TO_CHAR(logtime,'YYYY.MM.DD') AS logtime FROM "
+ "(SELECT rownum rn, tt. * FROM "
+ "(SELECT * FROM board ORDER BY SEQ DESC) tt) "
+ "WHERE rn>=? and rn<=?";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, startNum);
pstmt.setInt(2, lastNum);
res = pstmt.executeQuery();
while(res.next()) {
dto = new BoardDTO();
dto.setSeq(res.getInt("seq"));
dto.setId(res.getString("id"));
dto.setName(res.getString("name"));
dto.setSubject(res.getString("subject"));
dto.setContent(res.getString("content"));
dto.setHit(res.getInt("hit"));
dto.setLogtime(res.getString("logtime"));
list.add(dto);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
streamClose(res, pstmt, con);
}
return list;
}// boardList() end
public int getTotalArticle() {
int total =0;
try {
String sql = "SELECT COUNT(*) FROM board";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
res = pstmt.executeQuery();
if(res.next()) {
total =res.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
streamClose(res, pstmt, con);
}
return total;
}// getTotalArticle() end
public BoardDTO boardView(int seq) {
BoardDTO dto=null;
try {
String sql = "SELECT * FROM board WHERE seq=?";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, seq);
res = pstmt.executeQuery();
while(res.next()) {
dto = new BoardDTO();
dto.setSeq(res.getInt("seq"));
dto.setId(res.getString("id"));
dto.setName(res.getString("name"));
dto.setSubject(res.getString("subject"));
dto.setContent(res.getString("content"));
dto.setHit(res.getInt("hit"));
dto.setLogtime(res.getString("logtime"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
streamClose(res, pstmt, con);
}
return dto;
}
//조회수 증가
public void updateHit(int seq) {
try {
String sql ="UPDATE board SET hit=hit+1 where seq=?";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1,seq);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
streamClose(pstmt, con);
}
} // updateHit() end
//글수정
public int modify(BoardDTO dto) {
int su =0;
try {
String sql ="UPDATE board SET subject=?,content=? where seq=?";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setString(1, dto.getSubject());
pstmt.setString(2, dto.getContent());
pstmt.setInt(3, dto.getSeq());
su = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
streamClose(pstmt, con);
}
return su;
}//modify() end
public int delete(int seq) {
int su = 0;
try {
String sql = "delete from board where seq=?";
con = ds.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, seq);
su = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
streamClose(pstmt, con);
}
return su;
}
}
function checkBoardWrite(){
if(document.boardWriteForm.subject.value ==""){
alert("제목 입력");
document.boardWriteForm.subject.focus();
}else if(document.boardWriteForm.content.value ==""){
alert("내용 입력");
document.boardWriteForm.content.focus();
} else {
document.boardWriteForm.submit();
}
}
//글 수정
function checkBoardModify(){
if(document.boardModifyForm.subject.value ==""){
alert("제목 입력");
document.boardModifyForm.subject.focus();
}else if(document.boardModifyForm.content.value==""){
alert("내용 입력");
document.boardModifyForm.content.focus();
} else {
document.boardModifyForm.submit();
}
}
<%@page import="board.dao.BoardDAO"%>
<%@page import="board.dto.BoardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
BoardDAO dao = new BoardDAO();
BoardDTO dto = new BoardDTO();
dao.updateHit(seq);
dto = dao.boardView(seq);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>boardView.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
text-align: center;
}
</style>
</head>
<body>
<h1>글보기</h1>
<br>
<table>
<tr>
<td colspan="3"><%=dto.getSubject() %></td>
</tr>
<tr>
<td width="200px">글번호 : <%=dto.getSeq() %></td>
<td width="200px">작성자 : <%=dto.getName() %></td>
<td width="200px">조회수 : <%=dto.getHit() %></td>
</tr>
<tr>
<td colspan="3" height="300px" valign="top">
<pre><%=dto.getContent() %></pre>
</td>
</tr>
</table>
<br><br>
<input type="button" value="글목록" onclick="location.href='boardList.jsp?pg=<%=pg%>'"/>
<%if(session.getAttribute("memberId").equals(dto.getId())){ %>
<input type="button" value="글수정" onclick="location.href='boardModifyForm.jsp?pg=<%=pg%>&seq=<%=seq%>'">
<input type="button" value="글삭제" onclick="location.href='boardDelete.jsp?seq=<%=seq%>'">
<%} %>
</body>
</html>
<%@page import="board.dao.BoardDAO"%>
<%@page import="board.dto.BoardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int pg = Integer.parseInt(request.getParameter("pg"));
int seq = Integer.parseInt(request.getParameter("seq"));
BoardDTO dto = new BoardDTO();
BoardDAO dao = new BoardDAO();
dto = dao.boardView(seq);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>boardModifyForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
text-align: center;
}
textarea {
resize: none;
}
</style>
<script type="text/javascript" src="../script/boardScript.js?v=33"></script>
</head>
<body>
<h1>글수정</h1>
<br>
<form name="boardModifyForm" action="boardModify.jsp" method="post">
<input type="hidden" name="seq" value="<%=seq%>"/>
<input type="hidden" name="pg" value="<%=pg%>"/>
<table>
<tr>
<th>제 목</th>
<td><input type="text" name="subject" value="<%=dto.getSubject()%>" size="50" /></td>
</tr>
<tr>
<th>내 용</th>
<td>
<textarea rows="20" cols="52" name="content"><%=dto.getContent()%></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="완료" onclick="checkBoardModify()"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="board.dto.BoardDTO"%>
<%@page import="board.dao.BoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
String subject = request.getParameter("subject");
String content = request.getParameter("content");
BoardDTO dto = new BoardDTO();
dto.setSeq(seq);
dto.setSubject(subject);
dto.setContent(content);
BoardDAO dao = new BoardDAO();
int su = dao.modify(dto);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>boardModify.jsp</title>
<script type="text/javascript">
window.onload = function(){
<%if(su>0){%>
alert("글 수정 완료");
location.href="boardList.jsp?pg=<%=pg%>";
<%}else{%>
alert("글 수정 실패");
history.back(-1);
<%}%>
}
</script>
</head>
<body>
</body>
</html>
<%@page import="board.dao.BoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
int su = dao.delete(seq);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>boardDelete.jsp</title>
<script type="text/javascript">
window.onload = function(){
<%if(su>0){%>
alert("글 삭제 완료");
location.href="boardList.jsp?pg=1";
<%}else{%>
alert("글 삭제 실패");
history.back(-1);
<%}%>
}
</script>
</head>
<body>
</body>
</html>
< EL.txt >
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ex01.jsp</title>
</head>
<body>
<h1>표현 언어로 데이터 출력</h1>
<br>
<h2>
\${100 } : ${100 } <br>
\${"EL" } : ${"EL" } <br>
\${100+2 } : ${100+2 } <br>
\${"10"+2} : ${"10"+2 } <br> <!-- 숫자로 된 문자열과 숫자를 더하면 문자열이 자동으로 숫자로 변환 -->
\${null+2 } : ${null+2 } <br> <!-- null 은 0 -->
${"십" + 2 } 문자열과 숫자를 더할 수 없음
${"십" + "이" } --%><%-- 문자열끼리 더할 수 없음
</h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ex02.jsp</title>
</head>
<body>
\${10 + 10 } : ${10 + 10 } <br>
\${20 - 10 } : ${20 - 10 } <br>
\${10 * 10 } : ${10 * 10 } <br>
\${10 / 3 } : ${10 / 3 } <br>
\${10 div 3 } : ${10 div 3 } <br>
\${10 % 3 } : ${10 % 3 } <br>
\${10 mod 3 } : ${10 mod 3 } <br>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ex03.jsp</title>
</head>
<body>
<h1>비교 연산자</h1>
<h2>
\${10==10 } : ${10==10} <br>
\${10 eq 10 } : ${10 eq 10} <br>
\${"hi"=="hi" } : ${"hi"=="hi"} <br>
\${"hi"eq"hi" } : ${"hi"eq"hi"} <br>
<br>
\${10!=10 } : ${10!=10} <br>
\${10 ne 10 } : ${10 ne 10} <br>
\${"hi"!="hi" } : ${"hi"!="hi"} <br>
\${"hi" ne "hi" } : ${"hi" ne "hi"} <br>
<br>
\${10 > 10 } : ${10>10} <br>
\${10 gt 10 } : ${10 gt 10} <br>
\${10 < 11 } : ${10 < 11} <br>
\${10 lt 10 } : ${10 lt 10} <br>
<br>
\${10 >= 10 } : ${10>=10} <br>
\${10 ge 10 } : ${10 ge 10} <br>
\${10 <= 11 } : ${10 <= 11} <br>
\${10 le 10 } : ${10 le 10} <br>
</h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ex04.jsp</title>
</head>
<body>
<h1>논리 연산자</h1>
<br>
<h2>
\${(10 == 10) && (20 == 20) } : ${(10 == 10) && (20 == 20) } <br>
\${(10 == 20) and (20 == 20) } : ${(10 == 20) and (20 == 20) }<br>
<br>
\${(10 == 10) || (20 == 20) } : ${(10 == 10) || (20 == 20) }<br>
\${(10 == 20) or (20 == 20) } : ${(10 == 20) or (20 == 20) }<br>
<br>
\${!(10 == 10) } : ${!(10 == 10) } <br>
\${not(10 == 10) } : ${not(10 == 10) } <br>
</h2>
</body>
</html>
package bean;
import java.sql.Date;
public class MemberBean {
private String id;
private String pwd;
private String name;
private String email;
private Date date;
public MemberBean(String id, String pwd, String name, String email) {
super();
this.id = id;
this.pwd = pwd;
this.name = name;
this.email = email;
}
public MemberBean() {
super();
}
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;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
<%@page import="bean.MemberBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
MemberBean mbA = new MemberBean();
mbA.setId("001");
mbA.setPwd("1234");
mbA.setName("mbA");
mbA.setEmail("mbA@test.com");
%>
<jsp:useBean id="mbB" class="bean.MemberBean"/>
<jsp:setProperty name="mbB" property="name" value="mbB"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ex05.jsp</title>
</head>
<body>
<h1>empty</h1>
<br>
<h2>
\${empty "data" } : ${empty "data" }<br>
\${empty null } : ${empty null }<br>
\${empty "" } : ${empty "" }<br>
<br>
<!-- 액션태그로 해야 잘 나 옴 -->
\${empty mbA } : ${empty mbA } <br>
\${empty mbB } : ${empty mbB } <br>
\${not empty mbB } : ${not empty mbB } <br>
</h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>01_form.jsp</title>
</head>
<body>
<h1>param form</h1>
<br>
<form action="01_formRes.jsp" method="post">
data 1 : <input type="number" name="data_1"/>
<br><br>
data 2 : <input type="number" name="data_2"/>
<br><br>
<input type="submit" value="확인"/>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>01_formRes.jsp</title>
</head>
<body>
<h1>결과</h1>
<br>
<h2>
data 1 : ${param.data_1 } <br>
data 2 : ${param.data_2 } <br>
<br>
${param.data_1 } + ${param.data_2 } = ${param.data_1 + param.data_2} <br>
${param.data_1 } - ${param.data_2 } = ${param.data_1 - param.data_2} <br>
${param.data_1 } * ${param.data_2 } = ${param.data_1 * param.data_2} <br>
${param.data_1 } / ${param.data_2 } = ${param.data_1 / param.data_2} <br>
${param.data_1 } % ${param.data_2 } = ${param.data_1 % param.data_2} <br>
</h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_form.jsp</title>
</head>
<body>
<h1>param form2</h1>
<br>
<form action="02_formRes.jsp" method="post">
<h3>과목을 선택하세요</h3>
<input type="checkbox" name="subject" value="c"/> C <br>
<input type="checkbox" name="subject" value="java"/> Java <br>
<input type="checkbox" name="subject" value="python"/> Python <br>
<input type="checkbox" name="subject" value="jsp"/> Jsp <br>
<input type="checkbox" name="subject" value="spring"/> Spring <br><br>
<input type="submit" value="확인"/>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_formRes.jsp</title>
</head>
<body>
<h1>과목 확인</h1>
<br>
<h2>
param.subject : ${param.subject} <br>
<br>
paramValues.subject[0] : ${paramValues.subject[0]} <br>
paramValues.subject[1] : ${paramValues.subject[1]} <br>
paramValues.subject[2] : ${paramValues.subject[2]} <br>
paramValues.subject[3] : ${paramValues.subject[3]} <br>
paramValues.subject[4] : ${paramValues.subject[4]} <br>
</h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--
# MemberBean 의 정보(id, pwd, 이름, email) 을 입력받은 결과를
'memberPro.jsp' 에서 확인하는 페이지 구현
-->
<html>
<head>
<meta charset="UTF-8">
<title>memberForm.jsp</title>
</head>
<body>
<form name="memberForm" action="memberPro.jsp" method="post">
I D : <input type="text" name="id"><br>
이름 : <input type="text" name="name"><br>
비밀번호 : <input type="text" name="pwd"><br>
email : <input type="text" name="email"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<jsp:useBean id="mb" class="bean.MemberBean"/>
<jsp:setProperty name="mb" property="id" value="${param.id }"/>
<jsp:setProperty name="mb" property="pwd" value="${param.pwd }"/>
<jsp:setProperty name="mb" property="name" value="${param.name }"/>
<jsp:setProperty name="mb" property="email" value="${param.email }"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberPro.jsp</title>
</head>
<body>
아이디 : <jsp:getProperty property="id" name="mb"/> <br>
비밀번호 : <jsp:getProperty property="pwd" name="mb"/><br>
ㅇ;름 : <jsp:getProperty property="name" name="mb"/><br>
이메링 ; <jsp:getProperty property="email" name="mb"/><br>
</body>
</html>
<!-- ex02_param/01_form.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>01_form.jsp</title>
</head>
<body>
<h1>param form</h1>
<br/>
<form action="01_formRes.jsp">
데이터 1 : <input type="number" name="data_1"/>
<br/><br/>
데이터 2 : <input type="number" name="data_2"/>
<br/><br/>
<input type="submit" value="확인"/>
</form>
</body>
</html>
<!-- ex02_param/01_formRes.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>01_formRes.jsp</title>
</head>
<body>
<h1>결과</h1>
<br/>
<h2>
데이터 1 : ${param.data_1 }<br/>
데이터 2 : ${param.data_2 }<br/>
<br/>
${param.data_1 } + ${param.data_2 } = ${param.data_1 + param.data_2 }<br/>
${param.data_1 } - ${param.data_2 } = ${param.data_1 - param.data_2 }<br/>
${param.data_1 } * ${param.data_2 } = ${param.data_1 * param.data_2 }<br/>
${param.data_1 } / ${param.data_2 } = ${param.data_1 / param.data_2 }<br/>
${param.data_1 } % ${param.data_2 } = ${param.data_1 % param.data_2 }<br/>
</h2>
</body>
</html>
<!-- ex02_param/02_form.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_form.jsp</title>
</head>
<body>
<h1>param form2</h1>
<br/>
<form action="02_formRes.jsp" method="post">
<h3>과목을 선택하세요</h3>
<input type="checkbox" name="subject" value="c"/> C <br/>
<input type="checkbox" name="subject" value="java"/> Java <br/>
<input type="checkbox" name="subject" value="python"/> Python <br/>
<input type="checkbox" name="subject" value="jsp"/> Jsp <br/>
<input type="checkbox" name="subject" value="spring"/> Spring <br/>
<br/>
<input type="submit" value="확인"/>
</form>
</body>
</html>
<!-- ex02_param/02_formRes.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_formRes.jsp</title>
</head>
<body>
<h1>과목 확인</h1>
<br/>
<h2>
param.subject : ${param.subject }<br/>
<br/>
paramValues.subject[0] : ${ paramValues.subject[0] }<br/>
paramValues.subject[1] : ${ paramValues.subject[1] }<br/>
paramValues.subject[2] : ${ paramValues.subject[2] }<br/>
paramValues.subject[3] : ${ paramValues.subject[3] }<br/>
paramValues.subject[4] : ${ paramValues.subject[4] }<br/>
</h2>
</body>
</html>
<!-- 02_param/memberForm.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--
# MemberBean 의 정보(id, pw, 이름, email) 을 입력받은 결과를 'memberPro.jsp' 에서 확인하는 페이지를 구현하세요
-->
<html>
<head>
<meta charset="UTF-8">
<title>memberForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
</style>
</head>
<body>
<h1>정보 입력</h1>
<br/>
<form action="memberPro.jsp" method="post">
<table>
<tr>
<th width="120px">아이디</th>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<th width="120px">비밀번호</th>
<td><input type="text" name="pwd"/></td>
</tr>
<tr>
<th width="120px">이름</th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th width="120px">이메일</th>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="확인"/> <input type="reset" value="취소"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<!-- ex02_param/memberPro.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberPro.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
th {
width: 140px;
}
</style>
</head>
<body>
<h1>입력 정보</h1>
<br/>
<table>
<tr>
<th>아이디</th>
<th>비밀번호</th>
<th>이름</th>
<th>이메일</th>
</tr>
<tr>
<td>${param.id }</td>
<td>${param.pwd }</td>
<td>${param.name }</td>
<td>${param.email }</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
</style>
</head>
<body>
<h1>정보 입력</h1>
<br/>
<form action="forward.jsp" method="post">
<table>
<tr>
<th width="120px">아이디</th>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<th width="120px">비밀번호</th>
<td><input type="text" name="pwd"/></td>
</tr>
<tr>
<th width="120px">이름</th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th width="120px">이메일</th>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="확인"/> <input type="reset" value="취소"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
request.setAttribute("addr", "서울시 ㅇㄷ?");
%>
<jsp:forward page="memberPro.jsp"/>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberPro.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
th {
width: 140px;
}
</style>
</head>
<body>
<h1>입력 정보</h1>
<br/>
<table>
<tr>
<th>아이디</th>
<th>비밀번호</th>
<th>이름</th>
<th>이메일</th>
<th>주 소</th>
</tr>
<tr>
<td>${param.id }</td>
<td>${param.pwd }</td>
<td>${param.name }</td>
<td>${param.email }</td>
<td>${requestScope.addr }</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
</style>
</head>
<body>
<h1>정보 입력</h1>
<br/>
<form action="forward.jsp" method="post">
<table>
<tr>
<th width="120px">아이디</th>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<th width="120px">비밀번호</th>
<td><input type="text" name="pwd"/></td>
</tr>
<tr>
<th width="120px">이름</th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th width="120px">이메일</th>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="확인"/> <input type="reset" value="취소"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>pageContext.jsp</title>
</head>
<body>
<h1>contextPath</h1>
<br>
<h2>
<a href="http://localhost:8080/12_EL/ex04_pageContext/memberForm.jsp"> 정보 입력 </a>
</h2>
<br>
<!-- request 의 getContextPath() 메서드를 사용해서 context 가져오기 -->
<p><%=request.getContextPath() %></p>
<h2>
<a href="<%=request.getContextPath() %>/ex04_pageContext/memberForm.jsp"> 정보 입력 </a>
</h2>
<br>
<p>${pageContext.request.contextPath }</p>
<h2>
<a href="${pageContext.request.contextPath }/ex04_pageContext/memberForm.jsp"> 정보 입력 </a>
</h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
</style>
</head>
<body>
<h1>정보 입력</h1>
<br/>
<form action="memberPro.jsp" method="post">
<table>
<tr>
<th width="120px">아이디</th>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<th width="120px">비밀번호</th>
<td><input type="text" name="pwd"/></td>
</tr>
<tr>
<th width="120px">이름</th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th width="120px">이메일</th>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="확인"/> <input type="reset" value="취소"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<jsp:useBean id="mbA" class="bean.MemberBean"/><!-- MemberBean 의 mbA 객체 생성 -->
<jsp:setProperty name="mbA" property="*"/><!-- 전송된 정보를 bean 객체 값으로 설정 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberPro.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
th {
width: 140px;
}
</style>
</head>
<body>
<h1>입력 정보</h1>
<br/>
<table>
<tr>
<th>아이디</th>
<th>비밀번호</th>
<th>이름</th>
<th>이메일</th>
</tr>
<tr>
<td>${param.id }</td>
<td>${param.pwd }</td>
<td>${param.name }</td>
<td>${param.email }</td>
</tr>
<tr>
<td>${mbA.id }</td>
<td>${mbA.pwd }</td>
<td>${mbA.name }</td>
<td>${mbA.email }</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
</style>
</head>
<body>
<h1>정보 입력</h1>
<br/>
<form action="memberPro.jsp" method="post">
<table>
<tr>
<th width="120px">아이디</th>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<th width="120px">비밀번호</th>
<td><input type="text" name="pwd"/></td>
</tr>
<tr>
<th width="120px">이름</th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th width="120px">이메일</th>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="확인"/> <input type="reset" value="취소"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="bean.MemberBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<jsp:useBean id="mbA" class="bean.MemberBean"/><!-- MemberBean 의 mbA 객체 생성 -->
<jsp:setProperty name="mbA" property="*"/><!-- 전송된 정보를 bean 객체 값으로 설정 -->
<jsp:useBean id="list" class="java.util.ArrayList" type="java.util.ArrayList<bean.MemberBean>"/>
<%
MemberBean mbB = new MemberBean("son", "1234", "손흥민", "son@test.com");
list.add(mbA);
list.add(mbB);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>memberPro.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
th {
width: 140px;
}
</style>
</head>
<body>
<h1>입력 정보</h1>
<br/>
<table>
<tr>
<th>아이디</th>
<th>비밀번호</th>
<th>이름</th>
<th>이메일</th>
</tr>
<tr>
<td>${param.id }</td>
<td>${param.pwd }</td>
<td>${param.name }</td>
<td>${param.email }</td>
</tr>
<tr>
<td>${mbA.id }</td>
<td>${mbA.pwd }</td>
<td>${mbA.name }</td>
<td>${mbA.email }</td>
</tr>
<tr>
<td>${list[0].id }</td>
<td>${list[0].pwd }</td>
<td>${list[0].name }</td>
<td>${list[0].email }</td>
</tr>
<tr>
<td>${list[1].id }</td>
<td>${list[1].pwd }</td>
<td>${list[1].name }</td>
<td>${list[1].email }</td>
<td>${list[1].getId() }</td>
</tr>
</table>
</body>
</html>
<%@page import="bean.MemberBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
/*
# 바인딩 ( binding )
- 웹 프로그램이 실행되었을 때 데이터를 서블릿 관련 객체에 저장한 후
다른 서블릿 또는 JSP 에서 공유하는 방식
*/
request.setCharacterEncoding("utf-8");
MemberBean member = new MemberBean("member", "1111", "멤버", "member@test.com");
//bindingName / bindingValue
request.setAttribute("manA", member);
%>
<jsp:forward page="bindingResult.jsp"/>
<%@page import="bean.MemberBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>bindingResult.jsp</title>
</head>
<style type="text/css">
table, th, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
th {
width: 140px;
}
</style>
</head>
<body>
<h1>입력 정보</h1>
<br/>
<table>
<tr>
<th>아이디</th>
<th>비밀번호</th>
<th>이름</th>
<th>이메일</th>
</tr>
<tr>
<td>${manA.id }</td>
<td>${manA.pwd }</td>
<td>${manA.name }</td>
<td>${manA.email }</td>
</tr>
</table>
</body>
</html>