자바 servlet 실행 프로 세 스 코드 인 스 턴 스

이 글 은 자바 servlet 실행 프로 세 스 코드 인 스 턴 스 를 소개 합 니 다.
1.먼저 코드 를 아래 와 같이 첨부 합 니 다.
Servlet1.java

public class Servlet1 implements Servlet {
  @Override
  public void init(ServletConfig config) throws ServletException {

  }

  @Override
  public ServletConfig getServletConfig() {
    return null;
  }

  @Override
  public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    //      
    res.getWriter().write("hello servlet");

  }

  @Override
  public String getServletInfo() {
    return null;
  }

  @Override
  public void destroy() {

  }
}
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <display-name></display-name>

<servlet>
 <!--    serlvet-->
 <servlet-name>servlet1</servlet-name>
 <servlet-class>com.rookie.bigdata.Servlet1</servlet-class>
</servlet>

 <!-- servlet    -->
 <servlet-mapping>
  <servlet-name>servlet1</servlet-name>
  <url-pattern>/servlet1</url-pattern>
 </servlet-mapping>



 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>
2.전체 흐름 도 는 다음 과 같다.

3.상기 코드 에 대한 상세 한 절 차 는 다음 과 같다.
1.tomact 를 시작 하여 응용 프로그램 과 웹.xml 파일 을 불 러 옵 니 다.
2.http 접근 프로그램http://localhost:8080/servlet1,최종 적 으로 웹.xml 파일 을 통 해 com.rookie.bigdata.servlet 1 로 매 핑 합 니 다.
3.실례 화 된 Servlet 1 대상
4.Servlet 1 의 init 방법 을 호출 합 니 다.
5.service 방법 을 호출 하여 브 라 우 저 요청 을 받 습 니 다.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기