1 / 13

JSP 서블릿의 기초

JSP 서블릿의 기초. 유 명 훈 ymh627@kunsan.ac.kr 군산대학교 통계컴퓨터과학과 정보과학기술연구실 2012. 7. 12. 목차. 서블릿이란 ? 서블릿 클래스의 작성 , 컴파일 , 설치 , 등록 톰캣 관리자 프로그램 사용하기 웹 브라우저로부터 데이터 입력 받기. 서블릿이란 ?. 서블릿 클래스로 부터 만들어진 객체. 서블릿 클래스. 서블릿 객체. 서블릿. 인스턴스화. 초기화. 규칙에 따라 서블릿 클래스 올바른 작성. 웹 컨테이너에 설치. 등록.

Télécharger la présentation

JSP 서블릿의 기초

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSP서블릿의 기초 유 명 훈 ymh627@kunsan.ac.kr 군산대학교 통계컴퓨터과학과 정보과학기술연구실 2012. 7. 12

  2. 목차 서블릿이란? 서블릿 클래스의 작성, 컴파일, 설치, 등록 톰캣 관리자 프로그램 사용하기 웹 브라우저로부터 데이터 입력 받기 IST (Information Sciences & Technology) Laboratory

  3. 서블릿이란? 서블릿 클래스로 부터 만들어진 객체 서블릿 클래스 서블릿 객체 서블릿 인스턴스화 초기화 규칙에 따라 서블릿 클래스 올바른 작성 웹 컨테이너에 설치 등록 • 서블릿 클래스 • 웹 애플리케이션을 구현하기 위해 작성하는 코드 • 웹 컨테이너에 의해 수행 • 웹 서버가 여러 사용자(웹브라우저)로부터 동시에 접속을 받을 수 있어야 함(멀티스레드 방식으로 작동) • 웹 컨테이너가 만든 서블릿 수(싱글, 멀티) IST (Information Sciences & Technology) Laboratory

  4. 서블릿 클래스의 작성, 컴파일, 설치, 등록(1/4) javax.servlet.http.HttpServlet클래스를 상속 받아야 함 doGet() orDoPost() 안에 웹브라우저로 부터 요청이 왔을 때 해야 할 일 기술 HTML 문서는 doGet() orDoPost()의 두 번째 파라미터를 이용해 출력해야 함 구현 Servlet 인터페이스 GenericServlet클래스 HttpServlet클래스 상속 우리가 작성한 서블릿 클래스 • 서블릿 클래스의 작성을 위한 준비 IST (Information Sciences & Technology) Laboratory

  5. 서블릿 클래스의 작성, 컴파일, 설치, 등록(2/4) public class HundredServlet extends HttpServlet{ } public class HundredServlet extends HttpServlet{ public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{ inttotal = 0; for(intcnt=1; cnt <101; cnt++) total += cnt; } } • 서블릿 클래스 작성하기 • javax.servlet.http.HttpServlet클래스를 상속(public) • doGet() ordoPost()를 선언 • javax.servlet.http.HttpServletRequest, Javax.servlet.http.HttpServletResponse타입의 파라미터를 받아야 함 • Javax.servlet.http.HttpServletException, java.io.IOException선언 IST (Information Sciences & Technology) Laboratory

  6. 서블릿 클래스의 작성, 컴파일, 설치, 등록(3/4) PrinterWriter() 객체를 리턴하는메소드 printWriter writer = response.getWriter(); 웹 브라우저로 데이터를 출력 jdk 표준 라이브러리에 없기 때문 • 서블릿 클래스 작성하기 • 결과 출력 코드 작성 – doGet()의 두 번째 파라미터 이용 IST (Information Sciences & Technology) Laboratory

  7. 서블릿 클래스의 작성, 컴파일, 설치, 등록(4/4) http://localhost:8080/brain/hundred 웹 서버의 도메인 이름 포트 번호 웹 애플리케이션 디렉토리의 이름 • 서블릿 클래스 등록하기 • 웹 애플리케이션의 디플로이먼트디스크립터 파일에 등록 • 웹 애플리케이션의 WEB-INF 서브디렉터리 아래에 있는 web.xml파일을 말함 • webapps/examples/WEB-INF - web.xml IST (Information Sciences & Technology) Laboratory

  8. 톰캣 관리자 프로그램의 사용 방법(1/2) • 톰캣의 임무 • 웹브라우저로부터URL을 받아서 해당하는 HTML문서를 찾거나 서블릿or JSP 페이지를 호출 결과를 웹브라우저로 내보내는 것 • 톰캣 관리자 프로그램의 사용 방법 • http://localhost:8080/ IST (Information Sciences & Technology) Laboratory

  9. 톰캣 관리자 프로그램의 사용 방법(2/2) response.setContentType(“text/html;charset=euc-kr”) 이 문서의 내용은 HTML 문법으로 작성된 테스트 euc-kr문자셋(한글코드)으로 인코딩 됨 • 한글 HTML문서를 출력하는 서블릿 클래스 • doGet(), doPost()의두 번째 파라미터(HttpServletResponse)에 대해 setContentType()를 호출 IST (Information Sciences & Technology) Laboratory

  10. 웹 브라우저로부터 데이터 입력 받기(1/3) localhost:8080/brain/AdderInput.html localhost:8080/brain/adder • 웹 브라우저로부터 데이터 입력받는서블릿 클래스 • 화면 설계 -> URL 설정 -> 코딩작업 IST (Information Sciences & Technology) Laboratory

  11. 웹 브라우저로부터 데이터 입력 받기(2/3) localhost:8080/brain/BBSInput.html localhost:8080/brain/bbs-post request.setCharacterEncoding(“euc-kr”) • POST 메소드를 이용한 데이터 전송 • <FORM> 태그에 METHOD라는 애트리뷰트 추가 -> 값을 POST로 지정 IST (Information Sciences & Technology) Laboratory

  12. 웹 브라우저로부터 데이터 입력 받기(3/3) • 다양한 형태로 데이터 입력 받기 • 라디오 버튼, 체크 박스, 선택 상자 등 IST (Information Sciences & Technology) Laboratory

  13. 감사합니다유명훈ymh627@kunsan.ac.kr

More Related