model(JavaBean TV의 채널)
view(JSP page)
control
controller(Servlet, 리모콘으로 생각 하면 됨)
javax.servlet.http ← 서블릿 기본 패키지
Controller작성 단계
1. 클래스 생성후 HttpServlet 상속 받는다.
2. goGet, goPost, service 메서드를 오버라이딩 한다.(3개중 하나 이상, 시작부분이라 반드시 필요, service 메서드가 goGet, goPost를 처리해서 service 메서드만 오버라이딩 하면 됨)
package framework;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
public class HellowServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletRequest resp)
throws ServletException,IOException
{
}
public void doPost(HttpServletRequest req, HttpServletRequest resp)
throws ServletException,IOException
{
}
public void service(HttpServletRequest req, HttpServletRequest resp)
throws ServletException,IOException
{
}
}
webContent/web-inf/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.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_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>HelloServlet</servlet-name> <!-- 태그의 이름 -->
<servlet-class>framework.HelloServlet</servlet-class><!-- 패키지 풀 이름 -->
</servlet>
<servlet-mapping><!-- 서버에서 요청이 들어 왔을 때 제일 처음 찾는것 -->
<servlet-name>HelloServlet</servlet-name><!-- 호출 할 servlet 이름 -->
<url-pattern>/hello.kh</url-pattern>
<!-- 설정된 주소를 입력 하면 윗칸 이름 http://localhost:8000/framework/hello.kh -->
</servlet-mapping>
</web-app>