1. JSP Foundation
Understanding HTTP
– Http Uses TCP/IP
– 요청(request)와 응답(response)가 HTTP의 핵심
– HTTP 요청의 구성 : 헤더, 폼데이타, 두 종류 있다.(GET – 서버로 부터 데이터를 가져올 때 사용, POST – 서버에 데이터를 추가/수정 할 때 사용)
– HTTP 응답의 구성 : 컨텐츠 타입, 길이, HTTP 버전. 상태코드
Servlet & JSP
– 쓰레드 기반의 Servlet 만들었으나 HTML 출력하기 불편함
– 그리하여 JSP 만들었으나 자바 코드랑 섞여 있어서 디자인 요소랑 분리하고파짐
Web Appication Development 패턴
– Servlet 모델 :: 전부 서브릿으로
– 모델 1 :: 전부 JSP 로
– 모델 2 :: 서브릿(C), JSP(V)에 역할 나눠서 MVC 패턴 구현
Larning JSP Basics
– JSP 페이징 처리 과정 :: 맨 처음 요청 들어오면 JSP 페이지를 Servlet Java 코드로 변환한 뒤 컴파일 하여 class 파일 만들어서 그 클래스파일 로딩해서 처리하는데, 그 다음 요청 부터는 JSP 페이지가 바꼈는지 확인하고 바꼈으면 위에 과정 반복하고 아니면 그냥 처리.
– 라이프 사이클 메서드 :: jpsInit(), _jspService(). jspDestroy() 순으로 호출 되지만 _가 앞에 붙은 메소드는 오버라이딩 금지.(요 부분이 JSP 에서 Servlet 코드로 바뀔 때 만들어 지는 부분이니까 충돌 납니다.)
JSP 페이지 구조
– Direntives
– <%@ page import=”” extends=”” buffur=”” autoflush=”” %>
= <jsp:directive.page import=”” extends=”” buffur=”” autoflush=”” />
– <%@ include file=”” %>
= <jsp:directive.include file=”” />
– Declarations
– visibal to the rest of the page
– <%! int balance = 0; %>
– <jsp:declaration> int balance = 0; </jsp:declaration>
– Scriptlets
– 요 부분이 _jspService() 에 들어가게 됨
– <% %>
– <jsp:scriptlet> </jsp:scriptlet>
– Expressions
– <%= %>
– <jsp:expression> </jsp:expression>
EL 사용하기
– ${변수명.속성명}
JSTL 사용하기
– http://epro.tistory.com/79
1장 소스코드
– 테스트 데이터 넣을 DDL들
[#M_ more.. | less.. | INSERT INTO customer(id, lname, fname, age, sex, married, children, smoker)
VALUES (1, ‘Smith’, ‘Jane’, 26, ‘F’, ‘Y’, 2, ‘N’);
INSERT INTO customer(id, lname, fname, age, sex, married, children, smoker)
VALUES (2, ‘Doe’, ‘John’, 47, ‘M’, ‘N’, 0, ‘Y’);
INSERT INTO customer(id, lname, fname, age, sex, married, children, smoker)
VALUES (3, ‘Johnson’, ‘Michael’, 36, ‘M’, ‘Y’, 0, ‘N’);
INSERT INTO customer(id, lname, fname, age, sex, married, children, smoker)
VALUES (4, ‘Brooks’, ‘Susan’, 24, ‘F’, ‘N’, 1, ‘Y’);
INSERT INTO customer(id, lname, fname, age, sex, married, children, smoker)
VALUES (5, ‘Inman’, ‘Bernard’, 34, ‘M’, ‘N’, 0, ‘N’);
INSERT INTO product (id, description, base, lt30, lt50, gt50, m, f, married, children, smoker)
VALUES (1, ‘Preferred Healthcare’, 75.00, 1.0, 1.1, 1.3, 1.1, 1.2, 1.8, 1.4, 1.2);
INSERT INTO product (id, description, base, lt30, lt50, gt50, m, f, married, children, smoker)
VALUES (2, ‘Premium Healthcare’, 65.00, 1.0, 1.1, 1.3, 1.1, 1.2, 1.8, 1.4, 1.2);
INSERT INTO product (id, description, base, lt30, lt50, gt50, m, f, married, children, smoker)
VALUES (3, ‘Value Healthcare’, 50.00, 1.0, 1.1, 1.3, 1.1, 1.2, 1.8, 1.4, 1.2);
_M#]- JSP 코드
[#M_ more.. | less.. | <%@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core_rt” %>
<%@ taglib prefix=”sql” uri=”http://java.sun.com/jstl/sql_rt” %>
<sql:setDataSource
var=”datasource”
driver=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost:3306/quoting?useUnicode=true&chracterEncoding=UTF-8″
user=”jedi”
password=”jedi”
/>
<sql:query var=”customers” dataSource=”${datasource}”>
SELECT * FROM customer
</sql:query>
<html>
<head>
<title>Insurance Quoting System</title>
</head>
<body>
<font face=”Arial” />
<table width=”550″ border=”0″ align=”center”>
<tr>
<td bgcolor=”#006633″>
<div align=”center”>
<font size=”6″ color=”#FFFFFF”>
<b>Insurance Quoting System</b>
</font>
</div>
</td>
</tr>
<tr>
<td>
<p> </p>
<p> </p>
<p align=”center”><b>Customers</b></p>
<table width=”350″ border=”0″ align=”center”>
<c:forEach items=”${customers.rows}” var=”row”>
<tr>
<td width=”20″><c:out value=”${row.id}” /></td>
<td width=”70″><c:out value=”${row.lname}” /></td>
<td width=”70″><c:out value=”${row.fname}” /></td>
<td width=”40″>
<a href=”custMaint.jsp?id=${row.id}”&action=edit”>edit</a>
</td>
<td width=”40″>
<a href=”custMaint.jsp?id=${row.id}”&action=delete”>delete</a>
</td>
<td width=”110″>
<a href=”custMaint.jsp?id=${row.id}”&action=newQuote”>new quote</a>
</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
<tr>
<td>
<p> </p>
<p align=”center”><a href=”custMaint.jsp?action=add”>New Customer</a></p>
</td>
</tr>
</table>
</body>
</html>_M#]- 화면
느낀점 & 궁금증
– 코드가 DB 접근, 내용과 표현이 결합으로 인해 정신없슴.
– 어디서 에러가 날지 두려움.
– DB, 디자인, 자바코드 모두 알고 있어야 개발 가능.
– 아직도 이런 방법(모델1)으로 많이 개발을 하고 있을까?