자바 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 방법 을 호출 하여 브 라 우 저 요청 을 받 습 니 다.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.