2014-10-07

jsp2.0 2014. 10. 7. 10:44

1.Controller 생성

2. Super 인터페이스 생성]

3. web.xml - <servlet>태그 작성

4. propertis 파일 생성

5. Super 인터페이스를 구현하는 Action 클래스 생성

'jsp2.0' 카테고리의 다른 글

2014-10-13 Struts2  (0) 2014.10.13
2014-10-08  (0) 2014.10.08
10-01 슈퍼인터페이스  (0) 2014.10.01
모델2기반의 MVC패턴  (0) 2014.09.30
JSTL  (0) 2014.09.29
Posted by 5DMK2]발자국
,

10-01 슈퍼인터페이스

jsp2.0 2014. 10. 1. 10:41


같은 상속

같은 인터페이스 구현

둘중 하나가 되어있어야 다형성으로 변환 가능


MVC 패턴 Action 클래스 구현 방법

1. Super 인터페이스를 만든다.

2. Super 인터페이스는 request, response를 매개 변수를 정의한 추상메서드를 만든다.

3. Action클래스는 Super 인터페이스를 구현하고 오버라이딩한다.


Controller에서는 Action태그 호출한다


       1.request

요청 ----> Controller -----> Action

request       Service   <-----

2.return하면 view로 포워드함




외부파일

xml, properties(주소에 매칭되는 클래스 이름 지정되어 있어야 함)


외부파일은 WEB-INF폴더에 넣어야 함

파일 확장자는 .properties

주석은 #

/form.kh=framework.FormAction            

//패키지 이름까지 다 넣어 주어야 함     패키지 이름.XXX

/formPro.kh=framework.FormProAction

=앞에는 키 뒤에는 띄어쓰기 주의 (공백 있으면 안됨)




FormController

public class FormController extends HttpServlet{

// 서버 동작시 최초 1회 동작

public void init(ServletConfig config) throws ServletException {

}


java파일은 컴파일 해야 하지만 xml파일은 컴파일 할 필요가 없음



mvc 1 게시판과 mvc 게시판2 비교(차이점)

'jsp2.0' 카테고리의 다른 글

2014-10-08  (0) 2014.10.08
2014-10-07  (0) 2014.10.07
모델2기반의 MVC패턴  (0) 2014.09.30
JSTL  (0) 2014.09.29
2014-09-29 표현언어  (0) 2014.09.29
Posted by 5DMK2]발자국
,

모델2기반의 MVC패턴

jsp2.0 2014. 9. 30. 10:29

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>



'jsp2.0' 카테고리의 다른 글

2014-10-08  (0) 2014.10.08
2014-10-07  (0) 2014.10.07
10-01 슈퍼인터페이스  (0) 2014.10.01
JSTL  (0) 2014.09.29
2014-09-29 표현언어  (0) 2014.09.29
Posted by 5DMK2]발자국
,