chapter6.doc

Similar documents
I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

14-Servlet

TP_jsp7.PDF

04장

JAVA Bean & Session - Cookie

작성자 : 김성박\(삼성 SDS 멀티캠퍼스 전임강사\)

Data Provisioning Services for mobile clients

PowerPoint 프레젠테이션

07 자바의 다양한 클래스.key

PowerPoint 프레젠테이션

JavaGeneralProgramming.PDF

rmi_박준용_final.PDF

chapter5.doc

뇌를 자극하는 JSP & Servlet 슬라이드

PHP & ASP

09-interface.key

KYO_SCCD.PDF

중간고사


Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

Interstage5 SOAP서비스 설정 가이드

JMF2_심빈구.PDF

3ÆÄÆ®-14

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

J2EE Concepts

SK Telecom Platform NATE

Microsoft PowerPoint - web-part03-ch19-node.js기본.pptx

DocsPin_Korean.pages

신림프로그래머_클린코드.key

JMF3_심빈구.PDF

PowerPoint 프레젠테이션

Spring Data JPA Many To Many 양방향 관계 예제

Eclipse 와 Firefox 를이용한 Javascript 개발 발표자 : 문경대 11 년 10 월 26 일수요일

다른 JSP 페이지호출 forward() 메서드 - 하나의 JSP 페이지실행이끝나고다른 JSP 페이지를호출할때사용한다. 예 ) <% RequestDispatcher dispatcher = request.getrequestdispatcher(" 실행할페이지.jsp");

03장

MasoJava4_Dongbin.PDF

Ext JS À¥¾ÖÇø®ÄÉÀ̼ǰ³¹ß-³¹Àå.PDF

비긴쿡-자바 00앞부속

Microsoft PowerPoint 세션.ppt

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

chapter1,2.doc

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

Microsoft PowerPoint - aj-lecture6.ppt [호환 모드]

02 C h a p t e r Java

어댑터뷰

<4D F736F F F696E74202D203130C0E52EBFA1B7AF20C3B3B8AE205BC8A3C8AF20B8F0B5E55D>

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

목차 JEUS EJB Session Bean가이드 stateful session bean stateful sample 가이드 sample source 결과확인 http session에

C H A P T E R 2

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

쉽게 풀어쓴 C 프로그래밍

05-class.key

Microsoft PowerPoint - 웹프로그래밍_ ppt [호환 모드]

ch09

12-file.key

thesis

혼자서일을다하는 JSP. 이젠일을 Servlet 과나눠서한다. JSP와서블릿의표현적인차이 - JSP는 <html> 내에서자바를사용할수있는수단을제공한다. - 서블릿은자바내에서 <html> 을작성할수있는수단을제공한다. - JSP나서블릿으로만웹페이지를작성하면자바와다양한코드가

2파트-07

5장.key

쉽게 풀어쓴 C 프로그래밊

Multi Channel Analysis. Multi Channel Analytics :!! - (Ad network ) Report! -! -!. Valuepotion Multi Channel Analytics! (1) Install! (2) 3 (4 ~ 6 Page

PowerPoint 프레젠테이션

Data Provisioning Services for mobile clients

Dialog Box 실행파일을 Web에 포함시키는 방법

자바-11장N'1-502

Microsoft PowerPoint - 04-UDP Programming.ppt

Intro to Servlet, EJB, JSP, WS

OOP 소개

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

01-OOPConcepts(2).PDF

10.ppt

Microsoft PowerPoint - 7강.pptx


PHP & ASP

PowerPoint 프레젠테이션

Network seminar.key

Chap12

Week13

No Slide Title

Cache_cny.ppt [읽기 전용]

자바GUI실전프로그래밍2_장대원.PDF

Javascript.pages

하둡을이용한파일분산시스템 보안관리체제구현

Modern Javascript

뇌를 자극하는 JSP & Servlet 슬라이드

<4D F736F F F696E74202D20B5A5C0CCC5CDBAA3C0CCBDBA5F3130C1D6C2F75F31C2F7BDC32E >

API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

13ÀåÃß°¡ºÐ

2009년 상반기 사업계획

3장

PowerPoint Presentation

Microsoft PowerPoint - Java7.pptx

untitled

1217 WebTrafMon II

Web Service Computing

mytalk

1

국어부록표지

歯k"

Transcription:

Chapter 6. http..? ID. ID....... ecrm(ebusiness )., ecrm.. Cookie.....,. 20, 300 4. JSP. Cookie API javax.servlet.http. 3.

1. 2. 3. API. Cookie(String name, String value). name value. setxxx. getxxx. public int getmaxage() :.. public void setmaxage(int MaxAge) :.. 1. public String getdomain() :. public void setdomain(string Domain) :.. setdomain.. 2..yahoo.com yahoo.com. public String getpath() : path. public void setpath(string path) : path, path path path., jsp.boolpae.com/jsp/example.jsp jsp jsp.boolpae.com/xml. setpath( / ). / public void setvalue(string value) : value().. public String getvalue() :.

Example. JSP. List 6.1 setcookie.jsp <HTML> <HEAD> <TITLE> Set Cookie</TITLE> </HEAD> <BODY> <% for(int i=0;i<5;i++){ Cookie c = new Cookie("First Cookie"+i, "Value"+i); c.setmaxage(5); response.addcookie(c); c = new Cookie("Second Cookie"+i, "Value"+i); c.setmaxage(60*60); response.addcookie(c); %> <center> <h1> Cookie Example </h1> 5 10.<br> 5 5, 5 1. <hr> <a href="showcookie.jsp">cookie </a> </BODY> </HTML> List 6.1.

List 6.2 showcookie.jsp <HTML> <HEAD> <TITLE> show Cookie </TITLE> </HEAD> <BODY> <center> <h1> Cookie Example </h1> <table border=1> <tr><td bgcolor="gray"> </td> <td bgcolor="gray"></td></tr> <% Cookie[] c = request.getcookies(); for(int i=0;i<c.length;i++){ %> Cookie cookie = c[i]; <tr><td><%=cookie.getname()%></td><td><%=cookie.getvalue()%></tr> <% %> </table> </BODY>

</HTML> List 6.2 JSP. Cookie request.getcookies(). getname getvalue., 5. 5 5 5. [ ]

Second Cookie., JSESSIONID ID., ID. CookieUtil. List 6.3 CookieUtil.java package com.boolpae.jsp; import javax.servlet.http.cookie; public class CookieUtil{ public static String getvalue(cookie[] cookies, String name){ for(int i=0;i<cookies.length;i++){ if(name.equals(cookies[i].getname()))

return cookies[i].getvalue(); return null; public static Cookie getcookie(cookie[] cookies, String name){ for(int i=0;i<cookies.length;i++){ if(name.equals(cookies[i].getname())) return cookies[i]; return null; Cookie Cookie (value). static. JSP. List 6.4 CookitUtilExample.jsp <%@ page import="com.boolpae.jsp.cookieutil" %> <% Cookie c = new Cookie("Book", "JavaServer Pages"); response.addcookie(c); c = new Cookie("Jazz","BlueNote"); response.addcookie(c); %> <HTML> <HEAD> <TITLE> CookieUtilTest </TITLE> </HEAD> <BODY> <center> <h1>cookieutil Example</h1> <%= CookieUtil.getValue(request.getCookies(), "Book") %><br> <%= CookieUtil.getValue(request.getCookies(), "Jazz") %> </BODY> </HTML>

. null. Cookie. response Header. refresh... List 6.5 BlueCookie.java package com.boolpae.jsp; import javax.servlet.http.cookie; public class BlueCookie extends Cookie{ public static final String path = "/"; public BlueCookie(String name, String value, int maxage){ super(name, value); setmaxage(maxage); setpath(path);

maxage, path /. CookieUtilExample.jsp. List 6.6 CookieUtilExample.jsp <%@ page import="com.boolpae.jsp.*"%> <% Cookie c = new Cookie("Book", "JavaServer Pages"); response.addcookie(c); c = new Cookie("Jazz","BlueNote"); response.addcookie(c); c = new BlueCookie("Movie","JSA", 5); response.addcookie(c); %> <HTML> <HEAD> <TITLE> CookieUtilTest </TITLE> </HEAD> <BODY> <center> <h1>cookieutil Example</h1> <%= CookieUtil.getValue(request.getCookies(), "Book") %><br> <%= CookieUtil.getValue(request.getCookies(), "Jazz") %><br> <%= CookieUtil.getValue(request.getCookies(), "Movie") %> </BODY> </HTML>. 5 refresh Movie null.

response. addcookie. maxage 0 addcookie.. Cookie c = new Cookie( xxx, yyy ); response.addcookie(c); c = new Cookie( xxx, yyy ); c.setmaxage(0); response.addcookie(c); (?)maxage0. Session Http. Cookie.? URL-rewriting Hidden Form session. URL-rewriting sessionid, Hidden Form HTML form <input type= hidden name= name value= value > GET POST.

. Session. Session API Session javax.servlet.http.httpsession. HttpSession. public Object getattribute(string name) name value. String session Object. API 2.1. getvalue, 2.2 getattribute. getvalue.(aip deprecated ) pubic void setattribute(string name, Object value). Object. putvalue getvalue deprecated. public void removeattribute(string name). removevalue deprecated.. public Enumeration getattributenames() name Enumeration. public String getid() ID. ID. public long getcreationtime() long. millisecond. 197011 millisecond. public void invalidate().. public boolean isnew() boolean. invalidate

isnew true. Example... JSP JSP.,.,..., ( ). JSP Books JSP. CartPage JSP. CartPage.jsp. CartPage.jsp. (?) Request JSP. Cartpage.jsp... CartPage.jsp.. Book. List 6.7 Book.java package com.boolpae.jsp; public class Book{ private String isbn; private String title; private int price; public Book(String isbn, String title, int price){

this.isbn = isbn; this.title = title; this.price = price; public String getisbn(){ return isbn; public String gettitle(){ return title; public int getprice(){ return price;. isbn,, ( ).. BookList, BookList. List 6.8 BookList.java package com.boolpae.jsp; import java.util.vector; public class BookList{ private static Vector books= new Vector(); static{ books.addelement(new Book("A010101", "JavaServer Pages by ", 100 )); books.addelement(new Book("A020202", "JavaServer Pages by ", 40 )); public static Vector getbooks(){ return books;

public static Book getbook(string isbn){ if(isbn == null) return null; for(int i=0;i<books.size();i++){ Book book = (Book)books.elementAt(i); if(isbn.equals(book.getisbn())){ return book; return null; BookList. Book Book. static. static books. static static{. Vector ISBN ISBN Book.. List 6.9 Order.java package com.boolpae.jsp; public class Order{ private Book book; private int count = 1; public Order(Book book){ this.book = book; public Book getbook(){ return book; public void pluscount(){ count++; public void setcount(int c){ this.count = c; public int getcount(){ return count;

public int gettotalprice(){ return book.getprice()*count; Order. Book (count). 1 1 pluscount setcount. (Cart). List 6.10 Cart.java package com.boolpae.jsp; import java.util.vector; public class Cart{ private Vector ordered; public Cart(){ ordered = new Vector(); public Vector getordered(){ return ordered; public void addbook(string isbn){ for(int i=0;i<ordered.size();i++){ Order order = (Order)ordered.elementAt(i); if(isbn.equals(order.getbook().getisbn())){ order.pluscount(); return; Order neworder = new Order(BookList.getBook(isbn)); ordered.addelement(neworder); public void setcount(string isbn, int count){ Order order; for(int i=0;i<ordered.size();i++){ order = (Order)ordered.elementAt(i); if(isbn.equals(order.getbook().getisbn())){ if(count<=0){ ordered.removeelementat(i); else{ order.setcount(count); return;

Order neworder = new Order(BookList.getBook(isbn)); ordered.addelement(neworder);. Vector ordered Order Vector.. addbook, setcount., addbook..? addbook ISBN 1 ( -Order pluscount ),.(ordered Book addelement ) setcount. ISBN ISBN.( -Order setcount ) 0 0...,.. URL... JSP.. List 6.11 Books.jsp <%@ page import="java.util.vector" contenttype="text/html;charset=euc- KR" %> <HTML> <HEAD> <TITLE> Session Example </TITLE> <style> BODY, PRE {font-family:tahoma, ; font-size:8pt.blue{color:blue; font-size:15pt </style>

</HEAD> <BODY> <center> <h1> Shopping Cart Example </h1> <hr> <pre> <% Vector books = com.boolpae.jsp.booklist.getbooks(); for(int i=0;i<books.size();i++){ com.boolpae.jsp.book book = (com.boolpae.jsp.book)books.elementat(i); %> <font class= blue><%= book.gettitle()%></font><p> : <%=book.getprice()%> / ISBN: <%=book.getisbn()%> <form method='get' action='cartpage.jsp'> <input type='hidden' name="isbn" value='<%=book.getisbn()%>'> <input type='submit' value=' '> </form> <hr> <% %> </BODY> </HTML> JSP. 2. <form> CartPage.jsp. Form hidden ISBN. Book (!). page import.. List 6.11. [Books.jsp]

JSP.. ISBN CartPage.jsp. List 6.12 CartPage.jsp <%@ page import="java.util.vector" contenttype="text/html;charset=euc- KR" %> <jsp:usebean id="cart" class="com.boolpae.jsp.cart" scope="session" /> <HTML> <HEAD> <TITLE> add Cart </TITLE> </HEAD> <BODY> <center> <h1> Example</h1> <% String requestisbn = request.getparameter("isbn"); String requestcount = request.getparameter("count");

if(requestisbn!= null){ if(requestcount == null){ cart.addbook(requestisbn); else{ int parsecount; try{ parsecount = Integer.parseInt(requestCount); catch(numberformatexception e){ parsecount = 1; cart.setcount(requestisbn, parsecount); Vector ordered = cart.getordered(); if(ordered.size() == 0){ out.print("<h1> </h1>"); else{ out.print("<table border=1><tr><td>isbn</td><td> </td><td> </td><td> </td><td> </td>"); for(int i=0;i<ordered.size();i++){ com.boolpae.jsp.order order = (com.boolpae.jsp.order)ordered.elementat(i); int count = order.getcount(); com.boolpae.jsp.book book = order.getbook(); String isbn = order.getbook().getisbn(); String title = order.getbook().gettitle(); int price = book.getprice(); int totalprice = order.gettotalprice(); %> <tr> <td><%=isbn%></td> <td><%=title%></td> <td><%=price%></td> <td><form method="get" action="cartpage.jsp"> <input type="hidden" name="isbn" value="<%=isbn%>"> <input type="text" size="5" maxlength="2" name="count" value="<%=count%>"> <input type="submit" value=" "> </form> </td> <td><font color="red"><%=totalprice%></font></td> </tr> <% //end of for %> </table> : 1. <% //end of if %> </BODY> </HTML>

<jsp:usebean>. Session Session. <jsp:usebean id= cart class= com.boolpae.jsp.cart scope= session />? Cart. <% com.boolpae.jsp.cart cart = new com.boolpae.jsp.cart(); session.setattribute( cart, cart); %>.... String requestisbn = request.getparameter("isbn"); String requestcount = request.getparameter("count"); if(requestisbn!= null){ if(requestcount == null){ cart.additem(requestisbn); else{ int parsecount; try{ parsecount = Integer.parseInt(requestCount); catch(numberformatexception e){ parsecount = 1; cart.setcount(requestisbn, parsecount); isbn count. Books.jsp ISBN. cart.addbook. requestcount null Books.jsp. count null. null cart.setcount. requestisbn parsecount setcount int. request String int Integer.parseInt. int ( int ) NumberFormatException. Count1. parsecount setcount. 0.. <form> text

. form (count)isbn. Book Order. JavaServer Pages. [CartPage.jsp - 1],. 40 99. [CartPage.jsp 2]

... List 6.13 UserList.java package com.boolpae.jsp; import java.util.*; public class UserList{ private static Vector uservector = new Vector(); public static void adduser(string username){ String temp; for(int i=0;i<uservector.size();i++){ temp = (String)userVector.elementAt(i); if(username.equals(temp)){ return; uservector.addelement(username); public static void removeuser(string user){

String temp; for(int i=0;i<uservector.size();i++){ temp = (String)userVector.elementAt(i); if(user.equals(temp)){ uservector.removeelementat(i); return; public Vector getuser(){ return uservector; List 6.13. Vector, Vector. List 6.14. List 6.14 User.java package com.boolpae.jsp; import javax.servlet.http.*; public class User implements HttpSessionBindingListener{ private String username; public void setusername(string username){ this.username = username; UserList.addUser(userName); public void valuebound(httpsessionbindingevent event){ // UserListBean.addUser(userName); public void valueunbound(httpsessionbindingevent event){ UserList.removeUser(userName); javax.servlet.http.httpsessionbindinglistener. valuebound valueunbound.. Vector

Vector. valueunbound. jsp. List 6.15 UserList.jsp <HTML> <BODY> <H1>User List example</h1> <jsp:usebean id="userlist" class="com.boolpae.jsp.userlist" scope="application" /> <jsp:usebean id="user" class="com.boolpae.jsp.user" scope="session" /> <jsp:setproperty name="user" property="username" value="bluenote" /> <% java.util.vector uservector = userlist.getuser(); for(int i=0;i<uservector.size();i++){ out.print(uservector.elementat(i)); %> </BODY> </HTML>. List 6.15 UserList.jsp <jsp:setproperty>value.. BlueNote. value. 1 refresh. 1. jsp web.xml 1. List 6.16web.xml

. List 6.16 web.xml <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <session-config> <session-timeout> 1 </session-timeout> </session-config> </web-app> web.xml WEB-INF web.xml. JSP WEB-INF, META-INF. WEB-INF web.xml. jsp:setproperty value.