01 . CSL , Servlet , JSP package com . itwill . servlet ; import java . io . IOException ; import java . io . PrintWriter ; import java . text . SimpleDateFormat ; import java . util . Date ; import javax . servlet . ServletException ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; / / 1 . HttpServlet 클래스 를 상속 받 는다 . public class HelloServlet extends HttpServlet { / / 2 . doGet 메 서 드 를 오버 라 이 딩 한다 . ( doPost 메 서 드 또는 service 메 서드 도 존재 함 ) @ Override protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { / / 3 . 클라이언트 에 전송 하 는 데이터 타입 지정 response . setContentType ( " text / html ; charset = utf - 8 "); / / 4 . 클라이언트 에게 데이터 를 보낼 수 있 는 출력 스트림 을 얻 어 온다 . PrintWriter pw = response . getWriter ( ) ; / / 5 . 클라이언트 로 데이터 전송 String strHTML = ""; strHTML += " "; strHTML += " <! DOCTYPE html > "; strHTML += " < html > "; strHTML += " < head > "; strHTML += " < meta charset =\" UTF - 8 \"> "; strHTML += " < title > "; strHTML += " Hello 서블릿 "; strHTML += " </ title > "; strHTML += " </ head > "; strHTML += " < body > "; strHTML += " < h 1 > "; strHTML += " Hello 서블릿 ! !! "; strHTML += " </ h 1 > "; strHTML += " "; strHTML += " < hr / > "; for ( int i 1 = 0 ; i 1 < 7 ; i 1 ++) { strHTML += " 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . "; strHTML += " < br / > "; } strHTML += " "; strHTML += " <!-- Unuerder List ( ?) --> "; strHTML += " < ul > "; for ( int i 1 = 0 ; i 1 < 7 ; i 1 ++) { strHTML += " < li > "; strHTML += " 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . "; strHTML += " </ li > "; } strHTML += " </ ul > "; strHTML += " "; strHTML += " <!-- Order List --> "; strHTML += " < ol > "; for ( int i 1 = 0 ; i 1 < 7 ; i 1 ++) { strHTML += " < li > "; strHTML += " 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . "; strHTML += " </ li > "; } strHTML += " </ ol > "; strHTML += " < br / > "; strHTML += " < br / > "; strHTML += " "; strHTML += " < font color =' blue ' size =' 4 '> "; Date today = new Date ( ) ; SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy 년 MM 월 dd 일 HH 시 mm 분 "); String todayStr = sdf . format ( today ) ; strHTML += " 오늘 은 " + todayStr + " 입니다 . "; strHTML += " </ font > "; strHTML += " </ body > "; strHTML += " </ html > "; pw . println ( strHTML ) ; }} package com . itwill . servlet ; import java . io . IOException ; import java . io . PrintWriter ; import javax . servlet . ServletException ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; public class FirstServlet extends HttpServlet { @ Override protected void doGet ( HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException { resp . setContentType ( " text / html ; charset = utf - 8 "); PrintWriter pw = resp . getWriter ( ) ; String strHTML = ""; strHTML += " <! DOCTYPE html > "; strHTML += " < html > "; strHTML += " < head > "; strHTML += " < meta charset =\" UTF - 8 \"> "; strHTML += " < title > "; strHTML += " 반가워요 . 서블릿 "; strHTML += " </ title > "; strHTML += " </ head > "; strHTML += " < body > "; strHTML += " < center > "; strHTML += " < h 2 > "; strHTML += " 서블릿 은 쉬워요 . "; strHTML += " </ h 2 > "; strHTML += " < img alt =\" 고양이 \" src =\" tomcat . gif \"/> "; strHTML += " < br / > "; strHTML += " < br / > "; strHTML += " "; strHTML += " < h 2 > "; strHTML += " 서블릿 구구단 "; strHTML += " </ h 2 > "; strHTML += " < table border =\" 1 \" width =\" 600 \" bgcolor =\"# ccff 33 \" bordercolordark =\"# ff 6600 \" cellspacing =\" 0 \"> "; strHTML += " < tr > "; for ( int i 1 = 2 ; i 1 <= 9 ; i 1 ++) { strHTML += " < th > "; strHTML += " " + i 1 + " 단 "; strHTML += " </ th > "; } strHTML += " </ tr > "; strHTML += " "; for ( int i 1 = 1 ; i 1 <= 9 ; i 1 ++) { strHTML += " < tr align =\" center \"> "; for ( int i 2 = 2 ; i 2 <= 9 ; i 2 ++) { strHTML += " < td > "; strHTML += " " + i 2 + " * " + i 1 + " = " + ( i 2 * i 1 ) ; strHTML += " </ td > "; } strHTML += " </ tr > "; } strHTML += " </ table > "; strHTML += " </ center > "; strHTML += " </ body > "; strHTML += " </ html > "; pw . print ( strHTML ) ; }} package com . itwill . servlet ; import java . io . FileInputStream ; import java . io . IOException ; import javax . servlet . ServletException ; import javax . servlet . ServletOutputStream ; import javax . servlet . annotation . WebServlet ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; / ** * Servlet implementation class SendImage */@ WebServlet ( "/") public class SendImage extends HttpServlet { private static final long serialVersionUID = 1 L ; / ** * @ see HttpServlet # doGet ( HttpServletRequest request , HttpServletResponse response ) */ protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { response . setContentType ( " image / gif "); ServletOutputStream sos = response . getOutputStream ( ) ; String strFilePath = getServletContext ( ) . getRealPath ( "/ images / tomcat . gif "); System . out . println ( strFilePath ) ; FileInputStream fis = new FileInputStream ( strFilePath ) ; while ( true ) { int intReadByte = fis . read ( ) ; sos . write ( intReadByte ) ; if ( intReadByte == - 1 ) { break ; } } fis . close ( ) ; sos . flush ( ) ; sos . close ( ) ; } } package com . itwill . servlet ; import java . io . IOException ; import java . io . PrintWriter ; import javax . servlet . ServletException ; import javax . servlet . annotation . WebServlet ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; / ** * Servlet implementation class SendMSWord */@ WebServlet ( "/ SendMSWord ") public class SendMSWord extends HttpServlet { private static final long serialVersionUID = 1 L ; / ** * @ see HttpServlet # doGet ( HttpServletRequest request , HttpServletResponse response ) */ protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { response . setContentType ( " application / msword ; charset = utf - 8 "); PrintWriter out = response . getWriter ( ) ; String strHTML = ""; strHTML += " "; strHTML += " < table > "; strHTML += " < tr > "; strHTML += " < td > "; strHTML += " 번호 "; strHTML += " </ td > "; strHTML += " < td > "; strHTML += " 이름 "; strHTML += " </ td > "; strHTML += " < td > "; strHTML += " 전화 번호 "; strHTML += " </ td > "; strHTML += " </ tr > "; strHTML += " < tr > "; strHTML += " < td > "; strHTML += " 100 "; strHTML += " </ td > "; strHTML += " < td > "; strHTML += " 홍길동 "; strHTML += " </ td > "; strHTML += " < td > "; strHTML += " 010 - 1234 - 1234 "; strHTML += " </ td > "; strHTML += " </ tr > "; strHTML += " < tr > "; strHTML += " < td > "; strHTML += " 200 "; strHTML += " </ td > "; strHTML += " < td > "; strHTML += " 임꺽정 "; strHTML += " </ td > "; strHTML += " < td > "; strHTML += " 010 - 1234 - 4567 "; strHTML += " </ td > "; strHTML += " </ tr > "; strHTML += " </ table > "; out . println ( strHTML ) ; }} <! DOCTYPE html >< html > < head > < meta charset =" UTF - 8 "> < title > Hello 서블릿 </ title > </ head > < body > < h 1 > Hello 서블릿 ! !! </ h 1 > < hr / > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . < br / > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . < br / > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . < br / > <!-- Unuerder List ( ?) --> < ul > < li > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . </ li > < li > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . </ li > < li > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . </ li > </ ul > <!-- Order List --> < ol > < li > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . </ li > < li > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . </ li > < li > 안녕 하 세요 . 서블릿 을 연습 하 기 위한 예제 입니다 . </ li > </ ol > < br / > < br / > < font color =' blue ' size =' 4 '> 오늘 은 2013 년 10 월 30 일 14 시 18 분 입니다 . </ font > </ body ></ html > <! DOCTYPE html >< html > < head > < meta charset =" UTF - 8 "> < title > 반가워요 . 서블릿 </ title > </ head > < body > < center > < h 2 > 서블릿 은 쉬워요 . </ h 2 > < img alt =" 고양이 " src =" tomcat . gif "/> < br / > < br / > < h 2 > 서블릿 구구단 </ h 2 > < table border =" 1 " width =" 600 " bgcolor ="# ccff 33 " bordercolordark ="# ff 6600 " cellspacing =" 0 "> < tr > < th > 2 단 </ th > < th > 3 단 </ th > < th > 4 단 </ th > < th > 5 단 </ th > < th > 6 단 </ th > < th > 7 단 </ th > < th > 8 단 </ th > < th > 9 단 </ th > </ tr > < tr align =" center "> < td > 2 * 1 = 2 </ td > < td > 3 * 1 = 3 </ td > < td > 4 * 1 = 4 </ td > < td > 5 * 1 = 5 </ td > < td > 6 * 1 = 6 </ td > < td > 7 * 1 = 7 </ td > < td > 8 * 1 = 8 </ td > < td > 9 * 1 = 9 </ td > </ tr > </ table > </ center > </ body ></ html > <! DOCTYPE html > < html > < head > < meta charset =" UTF - 8 "> < title > Html 연습 </ title > </ head > < body > < h 1 > Hello Eclipse ! !! </ h 1 > < h 2 > Hello Eclipse ! !! </ h 2 > < h 3 > Hello Eclipse ! !! </ h 3 > < h 4 > Hello Eclipse ! !! </ h 4 > < h 5 > Hello Eclipse ! !! </ h 5 > < h 6 > Hello Eclipse ! !! </ h 6 > </ body ></ html > <? xml version =" 1 . 0 " encoding =" UTF - 8 "?>< web - app xmlns : xsi =" http : / / www . w 3 . org / 2001 / XMLSchema - instance " xmlns =" http : / / java . sun . com / xml / ns / javaee " xsi : schemaLocation =" http : / / java . sun . com / xml / ns / javaee http : / / java . sun . com / xml / ns / javaee / web - app _ 3 _ 0 . xsd " id =" WebApp _ ID " version =" 3 . 0 "> < display - name > 2013 - 10 - 30 </ display - name > < servlet > < servlet - name > FirstServlet </ servlet - name > < servlet - class > com . itwill . servlet . FirstServlet </ servlet - class > </ servlet > < servlet - mapping > < servlet - name > FirstServlet </ servlet - name > < url - pattern >/ FirstServlet </ url - pattern > </ servlet - mapping > < servlet > < servlet - name > HelloServlet </ servlet - name > < servlet - class > com . itwill . servlet . HelloServlet </ servlet - class > </ servlet > < servlet - mapping > < servlet - name > HelloServlet </ servlet - name > < url - pattern >/ HelloServlet </ url - pattern > </ servlet - mapping > < welcome - file - list > < welcome - file > index . html </ welcome - file > < welcome - file > index . htm </ welcome - file > < welcome - file > index . jsp </ welcome - file > < welcome - file > default . html </ welcome - file > < welcome - file > default . htm </ welcome - file > < welcome - file > default . jsp </ welcome - file > </ welcome - file - list ></ web - app >