반응형
web.xml servlet 매핑 설정.
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>pro5</display-name>
<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>
<servlet>
<servlet-name>aaa</servlet-name>
<servlet-class>sec01.ex01.FirstServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>bbb</servlet-name>
<servlet-class>sec01.ex01.SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>aaa</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>bbb</servlet-name>
<url-pattern>/second</url-pattern>
</servlet-mapping>
</web-app>
FirstServlet
package sec01.ex01;
import java.io.IOException;
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
public void init() throws ServletException{
System.out.println("init 메서드 호출");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
System.out.println("doGet메서드 호출");
}
@Override
public void destroy() {
System.out.println("destory 메서드 호출");
}
}
SecondServlet
package sec01.ex01;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SecondServlet extends HttpServlet{
@Override
public void init() throws ServletException{
System.out.println("Init 메서드 호출");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException{
System.out.println("doGet 메서드 호출");
}
@Override
public void destroy() {
System.out.println("destory 메서드 호출");
}
}
탐캣을 실행하시고 웹브라우저에 http://localhost:8080/pro5/first or second를 하시면 Init 이 한번 실행되고 doGet메소드는 주소를 한번 입력할때마다 계속 console에 log가 출력되게 됩니다.
반응형
'2020 > JSP SERVLET' 카테고리의 다른 글
게시판 글 삭제 기능 구현 (0) | 2020.01.06 |
---|---|
글 수정 기능 구현 (0) | 2020.01.03 |
글 상세 구현 (0) | 2020.01.03 |
게시판 글쓰기(파일첨부) 구현 (0) | 2020.01.03 |
모델 2 답변형 게시판 구현(게시판 테이블 생성) (0) | 2020.01.02 |