14-Servlet

Similar documents
JavaServletProgramming.PDF

JavaGeneralProgramming.PDF

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

2장 변수와 프로시저 작성하기

KYO_SCCD.PDF

J2EE Concepts

04장

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

서블릿의라이프사이클 뇌를자극하는 JSP & Servlet

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

chapter1,2.doc

<4D F736F F F696E74202D20B5A5C0CCC5CDBAA3C0CCBDBA5F3130C1D6C2F75F31C2F7BDC32E >

웹 개발자를 위한 서블릿/JSP

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

rmi_박준용_final.PDF

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

<param-value> 파라미터의값 </param-value> </init-param> </servlet> <servlet-mapping> <url-pattern>/ 매핑문자열 </url-pattern> </servlet-mapping> - 위의예에서 ServletC

Data Provisioning Services for mobile clients

chapter6.doc

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

Interstage5 SOAP서비스 설정 가이드

Data Provisioning Services for mobile clients

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

본 강의에 들어가기 전

02 C h a p t e r Java

PowerPoint 프레젠테이션

12-file.key

자바-11장N'1-502

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

歯JavaExceptionHandling.PDF

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

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

IBM blue-and-white template

PowerPoint Presentation

mytalk

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

3장

JSP 의내장객체 response 객체 - response 객체는 JSP 페이지의실행결과를웹프라우저로돌려줄때사용되는객체이다. - 이객체는주로켄텐츠타입이나문자셋등의데이터의부가정보 ( 헤더정보 ) 나쿠키 ( 다음에설명 ) 등을지정할수있다. - 이객체를사용해서출력의방향을다른

09-interface.key

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

PowerPoint 프레젠테이션

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

Chap12

JMF3_심빈구.PDF

PowerPoint 프레젠테이션

Microsoft PowerPoint - 03-TCP Programming.ppt

Microsoft PowerPoint - JasperReports 개발자 매뉴얼.ppt

JMF2_심빈구.PDF

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

歯Writing_Enterprise_Applications_2_JunoYoon.PDF

Microsoft PowerPoint - 04-UDP Programming.ppt

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

<4D F736F F D20C0DAB9D9C0A5BDBAC5B8C6AE2E646F63>

Microsoft PowerPoint - 4강.pptx

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

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

Intro to Servlet, EJB, JSP, WS

01-OOPConcepts(2).PDF

중간고사

User's Guide Manual

Microsoft PowerPoint - 7강.pptx

chapter3.doc

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

<property name="configlocation" value="classpath:/egovframework/sqlmap/example/sql-map-config.xml"/> <property name="datasource" ref="datasource2"/> *

Data Provisioning Services for mobile clients

교육2 ? 그림


No Slide Title

MasoJava4_Dongbin.PDF

Java

<4D F736F F F696E74202D203130C0E52EBFA1B7AF20C3B3B8AE205BC8A3C8AF20B8F0B5E55D>

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

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


Apache2 + Tomcat 5 + JK2 를 사용한 로드밸런싱과 세션 복제 클러스터링 사이트 구축

PowerPoint 프레젠테이션

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

ibmdw_rest_v1.0.ppt

<4D F736F F F696E74202D20C1A63235C0E520B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - RMI.ppt

untitled

PowerPoint 프레젠테이션

Cache_cny.ppt [읽기 전용]

( )부록

Chap7.PDF

Web Service Computing

TCP/IP Model

비긴쿡-자바 00앞부속

자바로

2파트-07

5장.key

untitled

MySQL-Ch05

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

05-class.key

Network Programming

OOP 소개

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

FileMaker ODBC and JDBC Guide

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

Transcription:

JAVA Programming Language Servlet (GenericServlet) HTTP (HttpServlet) 2

(1)? CGI 3 (2) http://jakarta.apache.org JSDK(Java Servlet Development Kit) 4

(3) CGI CGI(Common Gateway Interface) /,,, Client Server URL, Data HTML with Results Parameters Results CGI Program 5 (1) JSDK startserver stopserver Jakarta startup shutdown JSWDK(JavaServer Web Development Kit) startserver stopserver 6

(2) Jakarta Jakarta-tomcat // bin jakarta tomcat. classes classpath conf jakarta tomcat doc jakarta tomcat lib jakarta src jakarta webapps jakarta work JSP 7 (3) Jakarta bin startup shutdown 8

(4) Jakarta 9 (5) (HelloServlet.java) import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloServlet extends HttpServlet { public voiddoget(httpservletrequest req, HttpServletResponse res) throws ServletException, IOException { res.setcontenttype("text/html;charset=ksc5601"); try { out.close(); catch(exception e) { PrintWriter out = res.getwriter(); out.println("<html>"); out.println("<head><title>hello!! Servlet!!!</TITLE></HEAD>"); out.println("<h1>hello, Servlet!!</H1>"); out.println("<h2>. </H2>"); out.println("</body>"); out.println("</html>"); getservletcontext().log("error in HelloServlet:", e); 10

(6) (HelloServlet.java) HelloServlet.java, <jakarta-tomcat>/webapps/root/web-inf/classes/ 11 (1) - (request-response). FTP, HTTP HTTP init() Servers load and run Servlets The Servlets then accept zero or more requests from clients The Servlets then return data to the clients Servers terminate servlets service() destroy() 12

(2) Servlet interface implements GenericServlet class Override one or more of... class doget( ) dopost( ) service( )... extends HttpServlet extends MyServlet class doget( ) dopost( ) service( )... 13 (3) javax.servlet java.lang.object java.io.inputstream javax.servlet.genericservlet java.io.outputstream java. io.outputstream javax.servlet.servletinputstream javax.servlet.servletoutputstream javax.servlet.servlet javax.servlet.servletconfig javax.servlet.servletcontext javax javax.servlet.servletrequest javax.servlet.servletresponse javax.servlet.servletresponse javax.servlet.requestdispatcher javax.servlet.singlethreadmodel javax.servlet.singlethreadmodel 14

(4) Servlet, HTTP 1. javax.servlet.genericservlet 2. javax.servlet.httoservlet 15 (5) Servlet void destroy( ); //. ServletConfig getservletconfig(); // ServletConfig. // ServletConfig. String getservletinfo(); //. void init(servletconfig config); //,. void service(servletrequest req, ServletResponse res); //. 16

(6), init( ), destroy( ), finalize interface Servlet { WWW Request Response init(config) service(req, res) destroy() getservletconfig () getservletinfo() Load Unload MyServlet.class 17 (7)-GenericServlet GenericServlet Servlet ServletConfig implements, ServletConfig log( ) GenericServlet, service( ) 18

(8) MyServlet extends GenericServlet { Request ServletRequest req WWW WWW ServletResponse res Response ServletInputStream ServletOutputStream service(req, res) init(config) destroy() 19 (9) ServletRequest ServletRequest 20

(10) ServletResponse MIME ServletInputStream readline 21 (11) ServletOutputStream, ServletConfig ServletContext 22

GenericServlet(1) (GenericServlet3.java) import java.io.*; import javax.servlet.*; public class HelloGenericServlet3 extends GenericServlet { public void service(servletrequest req, ServletResponse res) throwsservletexception, IOException { res.setcontenttype("text/html; charset=euc-kr"); PrintWriter out=res.getwriter(); out.println("<html>"); out.println("<head><title>hello, GenericServlet Testing </TITLE></HEAD>"); out.println("<h1>hi, Hyun Hoon</H1>"); out.println("<h2>? </H2>"); out.println("</body>"); out.println("</html>"); 23 GenericServlet(2) (GenericServlet3.java) 24

(12)-HttpServlet HttpServlet HTTP GenericServlet HttpServlet service( ) // HttpServlet doget( ); // HTTP GET dopost( ); // HTTP POST doput( ); // HTTP PUT dodelete( ); // HTTP DELETE init( ); / destroy( ); // getservletinfo( ); // 25 (13) HTTP GET Request Response POST Request WWW HttpServletRequest req Response HttpServletResponse res PUT Request Response ServletInputStream MyServlet extends HttpServlet { doget(req, res) dopost(req, res) doput(req, res) dodelete(req, res) service( ) ServletOutputStream 26

(14) HttpServletRequest HttpServlet implements HttpServletResponse HTTP,, URL, 27 HttpServlet(1) (GET / POST ) import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloHttpServlet extends HttpServlet { public void doget(httpservletrequest req, HttpServletResponse res) throws IOException, ServletException { res.setcontenttype("text/html; charset=euc-kr"); PrintWriter out = res.getwriter(); out.println("<html>"); out.println("<head>"); out.println("<title>hello</title>"); out.println("</head>"); out.println("<h1> "+toksc5601(req.getparameter("name"))+"!</h1>"); out.println("<h3> "+toksc5601(req.getparameter("job"))+".</h3>"); out.println("</body>"); out.println("</html>"); 28

HttpServlet(2) (GET / POST ) public void dopost(httpservletrequest req, HttpServletResponse res) throws IOException, ServletException { res.setcontenttype("text/html; charset=euc-kr"); PrintWriter out = res.getwriter(); out.println("<html>"); out.println("<head>"); out.println("<title>hello</title>"); out.println("</head>"); out.println("<h1> "+toksc5601(req.getparameter("name"))+"!</h1>"); out.println("<h3> "+toksc5601(req.getparameter("job"))+".</h3>"); out.println("</body>"); out.println("</html>"); public static String toksc5601(string str) throws UnsupportedEncodingException { if(str == null) { return(null); return(new String(str.getBytes("8859_1"), "KSC5601")); // 29 HttpServlet(3) (GET ) 30

HttpServlet(4) (POST ) <HTML> <HEAD> <META http-equiv="content-type" content="text/html; charset=euc-kr"> <TITLE>Form Test</TITLE> </HEAD> <BODY> <H1>POST </H1> <P> <FORM action="http://203.253.24.110:8080/ servlet/hellohttpservlet" method="post" > : <input type="text" name="name" size=16><br> : <input type="text" name="job" size=40><br> <input type="submit" value=" "> Click 31 Session and Cookies(1) Session HttpSession 32

Session and Cookies(2) HttpSession Object Part of the Java ServletAPI Name=.. address=.. phone=.. Cookies SessionID=1XQ.. Server generate HttpSession SessionID= 1XQ.. Client Order=&*@jD Cookies SessionID=1XQ.. HttpSession SessionID= 1XQ.. name=.. address=.. Cookies SessionID=1XQ.. HttpSession SessionID= 1XQ.. name=.. address=.. order=.. 33 Session and Cookies(3) Cookies. Cookies Cookies Netscape ( ) 34

Session and Cookies(4) Cookies Client Name=.. address=.. phone=.. Order=&*@jD Cookies id=.. name=.. address=.. Cookies id=.. name=.. address=.. order=.. Cookies id=.. name=.. address=.. Server generate Cookies id=.. name=.. address=.. generate Cookies order=... 35 Session and Cookies(5) Cookies import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public classloginservletextends HttpServlet{ public void dopost(httpservletrequest req, HttpServletResponse res) throws ServletException, IOException{ res.setcontenttype("text/html;charset=euc-kr"); PrintWriter out = res.getwriter(); out.println("<html>"); out.println("<head>"); out.println("<title>login</title>"); out.println("</head>"); String user = req.getparameter("user"); user = newstring(user.getbytes("iso-8859-1"), "EUC-KR"); String pass = req.getparameter("pass"); res.addcookie(logincookie); res.addcookie(usercookie); out.println("<h1>.</h1><br>"); out.println( <A HREF=\"http://203.253.24.110:8080/servlet/StartServiceServlet\"> "); else { out.println("<h1>.</h1><br>"); out.println("<a HREF=\"/Login.html\"> "); out.println("</body>"); out.println("</html>"); out.close(); if(("casper".equals(user)) && ("casper".equals(pass))) { Cookie logincookie = newcookie("bbs -casper", "Login"); Cookie usercookie = newcookie("username", user); 36

Session and Cookies(6) Cookies import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public classstartserviceservletextends HttpServlet{ public void doget(httpservletrequest req, HttpServletResponse res) throws IOException, ServletException{ res.setcontenttype("text/html;charset=euc-kr"); PrintWriter out = res.getwriter(); out.println("<html>"); out.println("<head>"); out.println("<title>hello</title>"); out.println("</head>"); int match=0; String user = null; boolean login=false; Cookie[] cookies = req.getcookies(); if(cookies!= null) { for(int i=0;i<cookies.length;i++) { if(("bbs -casper".equals(cookies[i].getname())) && ("Login".equals(cookies[i].getValue()))) { login = true; match++; else if("username".equals(cookies[i].getname())) { user = cookies[i].getvalue(); match++; if(match >= 2) { break; out.println("<center>"); if(login) { out.println("<h2> "+user+"!</h2>"); out.println("<h3>.</h3>"); else { out.println("<h2>.</h2><br>"); out.println("<a HREF=\"/Login.html\"> "); out.println("</body>"); out.println("</html>"); public void dopost(httpservletrequest req, HttpServletResponse res) throws IOException, ServletException{ doget(req, res); 37 Session and Cookies(7) 38