Servlet / JSP 전 혜 영전 혜 영 전 혜 영전 혜 영
0. 목차 Web Application Technologies Servlet Server Simple Servlet Servlet / HTML Form Deployment Descriptor Servlet Context MVC Parrern Cookie / Session Error Handling
Web Application Technologies
Client-Server Architecture
HTTP C-S Architecture
CGI Programs on the Web Server
기존 CGI Programs
Servlets on the Web Server
Servlet Program
The Model2 Architecture
J2EE Architecture
Web Application Migration
Servlet Engine
Servlet Server Programs JDK 설치 JAVA_HOME=C:\J2SDK1.X Path=.;%JAVA_HOME\bin classpath=.;C:\....\X.jar Servlet Server TOMCAT( RESIN( Home 경로 추가 servlet.jar 경로 classpath 에 추가
TOMCAT ./Tomcat/bin\startup.bat
TOMCAT Configuration Tomcat bin startup.bat, shutdown.bat conf server.xml, web.xml webapps ROOT WEB-INF Classes web.xml html, jsp work
Resin ./resin\bin/httpd.exe
Resin
Resin Configuration bin httpd.exe conf resin.conf, app-default.xml doc WEB-INF classes work html, jsp lib resin.jar webapps config.xml
Simple Servlet
The NetServer Architecture
The Generic Servlet API
Generic Servlet Code import javax.servlet.GenericServlet; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import java.io.PrintWriter; import java.io.IOException; public class HelloServlet extends GenericServlet { public void service(ServletRequest request, ServletResponse response) throws IOException { PrintWriter out = response.getWriter(); out.println(“Hello, World!!”); out.close(); }
Hypertext Transfer Protocol
HTTP (Hypertext Transfer Protocol) request/reponse header entity body HTTP 동작 방식 GET POST HEAD PUT DELETE TRACE OPTIONS
GET url HTTP/1.1 요청에 대한 정보 GET/POST Request POST url HTTP/1.1 요청에 대한 정보 요청의 일부로 전송되는 정보
GET 소량의 데이타 전송 HTTP 의 헤더로 데이타 전송 URL 창에 보내는 데이타가 보임 URL 창에 이라고 요청하 는 것 자체가 GET 방식 ( default ) POST HTTP 의 몸체로 데이타 전송 대량의 데이타 ( 예, 파일전송 ) 전송시 URL 창에 데이타가 안보이기에 보안에 좋음
Web Container Architecture
SequenceDiagram - HTTP GetRequest
The Http Servlet API
HttpServlet Code import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.PrintWriter; import java.io.IOException; public class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=euc-kr"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" "); out.println(" Hello Servlet "); out.println(" "); out.println(" Hello, World "); out.println(" "); out.println(" "); out.close(); }
Servlet Life Cycle
Servlet / HTML Form
FORM tag action : 웹 서버에 전달되어 처리될 CGI 프로 그램 주소 method : get/post enctype : 인코딩 타입 target : CGI 프로그램이 처리후 결과를 보여 줄 위치
HTML Form Components
Servlet API
Deployment Descriptor
web-app icon display-name description distributable context-param filter filter-mapping listener servlet servlet-mapping session-config mime-mapping welcome-file-list error-page taglib resource-env-ref resource-ref security-constraint login-config security-role env-entry ejb-ref ejb-local-ref Filter icon filter-name display-name description filter-class init-param param-name param-value description filter-mapping filter-name url-parrern servlet-name servlet icon servlet-name display-name description servlet-class jsp-file init-param param-name param-value servlet-mapping servlet-name url-pattern
Initialization Parameters (web.xml) simpleServlet ServletTest dbDriver com.mysql.jdbc.Driver
Initialization Parameters (servlet.java) public class ServletTest extends HttpServlet{ private String driver; public void init(){ Driver=getInitParameter(“dbDriver”); } public void doGet(HttpServletRequest, httpServletResponse) throws ServletException, IOException{ … Out.println(driver);.. }
Servlet Config
Servlet Context
MVC Parrern
Cookie / Session
Error Handling