๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/Spring

WAS ๋™์ž‘๊ณผ์ • / ์„œ๋ธ”๋ฆฟ(Servlet) / Servlet ๊ตฌํ˜„ / ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ

by 1mj 2022. 1. 24.

๋ชฉ์ฐจ

 

WAS ๋™์ž‘ ๊ณผ์ •

 

  1. ์›น ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ web.xml์„ ์ฐธ์กฐํ•˜์—ฌ Servlet์— ๋Œ€ํ•œ Thread๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์š”์ฒญ(httpServletRequest) ๋ฐ ์‘๋‹ต(httpServletResponse) ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ „๋‹ฌํ•œ๋‹ค.
  2. ํ˜ธ์ถœ๋œ ์„œ๋ธ”๋ฆฟ์˜ ์ž‘์—…์„ ๋‹ด๋‹นํ•˜๊ฒŒ ๋œ ์Šค๋ ˆ๋“œ๋Š” ๊ทธ์— ๋งž๋Š” doGet() ๋˜๋Š” doPost() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด ์ƒ์„ฑ๋œ ๋™์  ํŽ˜์ด์ง€๋ฅผ Response ๊ฐ์ฒด์— ๋‹ด์•„ ์ปจํ…Œ์ด๋„ˆ์— ์ „๋‹ฌํ•œ๋‹ค.
  3. ์ปจํ…Œ์ด๋„ˆ๋Š” ์ „๋‹ฌ ๋ฐ›์€ Response ๊ฐ์ฒด๋ฅผ HttpResponse ํ˜•ํƒœ๋กœ ๋ฐ”๊พธ์–ด Web Server์— ์ „๋‹ฌํ•˜๊ณ  ์ƒ์„ฑ๋œ ์Šค๋ ˆ๋“œ๋ฅผ ์ข…๋ฃŒํ•˜๊ณ  ๊ฐ์ฒด๋ฅผ ์†Œ๋ฉธ์‹œํ‚จ๋‹ค.
[ Web Server ์™€ WAS์˜ ์ฐจ์ด ]
๐Ÿ“š Web Server (์›น ์„œ๋ฒ„)
Static; ๋ฐ”๋€Œ์ง€ ์•Š๋Š” Page
ํŒŒ์ผ ๊ฒฝ๋กœ ์ด๋ฆ„์„ ๋ฐ›์•„ ๊ฒฝ๋กœ์™€ ์ผ์น˜ํ•˜๋Š” ํŒŒ์ผ ๋ฐ˜ํ™˜
image, html, css, javascript ํŒŒ์ผ๊ณผ ๊ฐ™์ด ์ปดํ“จํ„ฐ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ํŒŒ์ผ์„ ๋ฐ˜ํ™˜
๋„คํŠธ์›Œํฌ ๋ง์— ์ข…์†๋˜์ง€ ์•Š์Œ
ex) IIS, apache, tMax, WebtoB

๐Ÿ“š WAS = ์›น ์„œ๋ฒ„ + ์›น ์ปจํ…Œ์ด๋„ˆ
Dynamic; ์ธ์ž์— ๋”ฐ๋ผ ๋ฐ”๋€Œ๋Š” Page
์›น ์„œ๋ฒ„๊ฐ€ ๋‹จ๋…์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์กฐํšŒ๋‚˜ ๋‹ค์–‘ํ•œ ๋กœ์ง ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•œ ๋™์  ์ปจํ…์ธ  ์ œ๊ณต
Servlet, JSP, ASP, PHP ๋“ฑ์˜ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์‚ฌ์šฉ๋จ
ex) tomcat, JBOSS, tMax jeus, BEA Web Logic, IBM Webspere

์›น ์„œ๋ฒ„์™€ WAS๋Š” ๊ฐ๊ฐ ๋…๋ฆฝ์ ์œผ๋กœ ์กด์žฌํ•  ์ˆ˜ ์žˆ๊ณ , ์›น ์„œ๋ฒ„ ์—†์ด WAS๋งŒ ์กด์žฌํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
WAS ์ž์ฒด๋กœ ์›น ์„œ๋ฒ„์˜ ์—ญํ• ๊นŒ์ง€ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์„œ๋ธ”๋ฆฟ (Servlet)

๋™์ ์ธ ์›น ํŽ˜์ด์ง€ ์ƒ์„ฑ์„ ์œ„ํ•œ ์ž๋ฐ” ๊ธฐ๋ฐ˜ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์ž๋ฐ” ํด๋ž˜์Šค์˜ ์ผ์ข…์ด๋‹ค.

  • ์ž๋ฐ” ํ”Œ๋žซํผ์—์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์˜ ํ•ต์‹ฌ ์š”์†Œ
  • MVC ํŒจํ„ด์„ ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๊ณ  ์ปจํ…Œ์ด๋„ˆ์™€ ๋ฐ€์ ‘ํ•œ ์„œ๋ฒ„ ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ ๊ฐ€๋Šฅ
  • Html์„ ์‚ฌ์šฉํ•˜์—ฌ Response ํ•จ
  • Java Thread๋กœ ๋™์ž‘ํ•จ
  • ์šด์˜์ฒด์ œ๋‚˜ ํ•˜๋“œ์›จ์–ด์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์•„ ๋‹ค์–‘ํ•œ ์„œ๋ฒ„ ํ™˜๊ฒฝ์— ์ด์‹ ๊ฐ€๋Šฅ
  • Jsp๋Š” ์„œ๋ธ”๋ฆฟ ๊ธฐ๋ฐ˜์˜ ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ˆ ๋กœ ๋‚ด๋ถ€์ ์œผ๋กœ ์„œ๋ธ”๋ฆฟ์œผ๋กœ ๋ณ€ํ™˜๋˜์–ด ์‹คํ–‰๋จ

 

Servlet ๊ตฌํ˜„

Jsp์™€ Servlet ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐฉ๋ฒ•์„ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

Jsp์—์„œ GET์ด๋‚˜ POST ๋ฐฉ์‹์œผ๋กœ Requestํ•˜๋ฉด Servlet์—์„œ ๋‚ด์šฉ์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•œ ํ›„ Response ํ•˜๋Š” ๊ณผ์ •๋งŒ ๊ฐ„๋‹จํžˆ ์ถ”๋ ธ๋‹ค.

 

โ‘  ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ ์ต์Šคํ”Œ๋กœ๋Ÿฌ ํƒญ์—์„œ ์˜ค๋ฅธ์ชฝ ๋งˆ์šฐ์Šค๋ฅผ ํด๋ฆญํ•ด [New] > [Other] > web ๊ฒ€์ƒ‰ > Dynamic Web Project  ์„ ํƒํ•˜์—ฌ ์›น ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

์ต์Šคํ”Œ๋กœ๋Ÿฌ ํƒญ์—์„œ ์˜ค๋ฅธ์ชฝ ๋งˆ์šฐ์Šค๋ฅผ ํด๋ฆญํ•ด [New] > [Other]
Dynamic Web Project ์ƒ์„ฑ
์›ํ•˜๋Š” ํ”„๋กœ์ ํŠธ๋ช… ์ž…๋ ฅ ํ›„ Finish

 

โ‘ก Servlet ํŒŒ์ผ ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ๋ช… > src ์•„๋ž˜์— Servlet ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค.

HttpServlet์„ ์ƒ์†๋ฐ›๊ณ  doGet(), doPost() ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

src์—์„œ ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ํด๋ฆญ ํ›„ [New] > [Other] > [Servlet ๊ฒ€์ƒ‰]
์›ํ•˜๋Š” ํŒจํ‚ค์ง€ ๊ฒฝ๋กœ, ํด๋ž˜์Šค๋ช… ์ž‘์„ฑ
์ƒ์„ฑ๋œ Servlet ํŒŒ์ผ์˜ ๊ตฌ์กฐ

 

์ƒ์„ฑ๋œ Test.java ํŒŒ์ผ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

package test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Test
 */
@WebServlet("/Test")
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Test() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

 

โ‘ข Jsp ํŒŒ์ผ ์ƒ์„ฑ

WebContent ์•„๋ž˜์— [New] > [Others] > jsp ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค.

์ƒ์„ฑ๋œ ํŒŒ์ผ ๊ตฌ์กฐ

 

Jsp ํŒŒ์ผ์—๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž…๋ ฅ ๊ฐ’์„ post ํ˜•์‹์œผ๋กœ ๋„˜๊ธฐ๋„๋ก ์ž‘์„ฑํ–ˆ๋‹ค.

action ๊ฐ’์€ "/ํ”„๋กœ์ ํŠธ๋ช…/์„ค์ •ํ•œ๊ฒฝ๋กœ"์™€ ๊ฐ™์ด ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค. (tomcat ๊ธฐ๋™ ์‹œ path ๋ณ€๊ฒฝ ์•ˆ ํ–ˆ์„ ๋•Œ ๊ธฐ์ค€)

์„ค์ •ํ•œ ๊ฒฝ๋กœ๋Š” ์•„๋ž˜ web.xml ํŒŒ์ผ์—์„œ ์„ค๋ช…ํ•  ๊ฒƒ์ด๋‹ค.

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Servlet Test Page</title>
</head>
<body>
	<div>
		<form method="post" action="/servletTest/test">
			name: <input type="text" name="name"><br />
			age: <input type="text" name="age">
			<input type="submit" value="์ „์†ก">
		</form>
	</div>
</body>
</html>
๐Ÿ“š WEB-INF ํด๋”
WebContent/WEB-INF ํด๋”๋Š” ์›น ์„œ๋ฒ„๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ์ผ์ด ๋“ค์–ด์žˆ๋Š” ์ค‘์š”ํ•œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์™ธ๋ถ€์—์„œ ์ง์ ‘ ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค.
/WEB-INF ๋‚ด ํŒŒ์ผ์„ ์„œ๋น„์Šคํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.
โ‘  web.xml ์„ค์ •์„ ํ†ตํ•ด์„œ ์ ‘๊ทผํ•œ๋‹ค.
โ‘ก @WebServlet ์–ด๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•ด์„œ ์ ‘๊ทผ ์‹œ ์‚ฌ์šฉํ•˜๋Š” URI๋ฅผ ์ง€์ •ํ•œ๋‹ค.
ex) ์ƒ์„ฑํ•œ ์„œ๋ธ”๋ฆฟ ํŒŒ์ผ์—์„œ @WebServlet("/Test")์™€ ๊ฐ™์ด ์‚ฌ์šฉ

 

โ‘ฃ web.xml ํŒŒ์ผ ์ƒ์„ฑ

Jsp ์™€ Servlet ํด๋ž˜์Šค๋ฅผ ๋งคํ•‘ํ•˜๊ธฐ ์œ„ํ•œ xml๋กœ <Servlet-mapping> ๋‚ด <url-pattern>์„ ์ง€์ •ํ•œ๋‹ค.

WEB-INF ์—์„œ ์˜ค๋ฅธ์ชฝ ๋งˆ์šฐ์Šค ํด๋ฆญ ํ›„ xml ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•œ๋‹ค.

web.xml ์ƒ์„ฑ ํ›„ ํŒŒ์ผ ๊ตฌ์กฐ

 

- <welcome-file>

test.jsp ํŒŒ์ผ์„ ๋””ํดํŠธ ๊ฒฝ๋กœ๋กœ ์„ค์ •ํ•ด์ค€๋‹ค.

๊ฒฝ๋กœ ์—†์ด localhost:8080/servletTest์™€ ๊ฐ™์€ ์š”์ฒญ์ด ์˜ค๋ฉด test.jsp ํŽ˜์ด์ง€๋กœ ์ด๋™์‹œํ‚จ๋‹ค.

- <Servlet-mapping>

<url-pattern>์ด /test๋กœ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ServletTest์ด๋ฆ„์„ ๊ฐ€์ง„ ๊ฒฝ๋กœ์ธ servletTest.Test๋กœ ์ด๋™ํ•œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด localhost:8080/servletTest/test์™€ ๊ฐ™์€ ์š”์ฒญ์ด ์˜ค๋ฉด ์„œ๋ธ”๋ฆฟ ํŒŒ์ผ์˜ Test ๊ฒฝ๋กœ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค.

์—ฌ๊ธฐ์„œ Test๋Š” ์„œ๋ธ”๋ฆฟ ํŒŒ์ผ์˜ @WebServlet ์–ด๋…ธํ…Œ์ด์…˜ ๊ฒฝ๋กœ์ด๋‹ค.

<?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>test</display-name>
	<welcome-file-list>
		<welcome-file>test.html</welcome-file>
		<welcome-file>test.htm</welcome-file>
		<welcome-file>test.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>ServletTest</servlet-name>
		<servlet-class>servletTest.Test</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>ServletTest</servlet-name>
		<url-pattern>/test</url-pattern>
	</servlet-mapping>
</web-app>

 

โ‘ค POST๋กœ ์š”์ฒญ์ด ์˜ฌ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌํ•  ๋‚ด์šฉ ์ž‘์„ฑ

Jsp์—์„œ POST ๋ฐฉ์‹์œผ๋กœ name, age ๊ฐ’์„ ๋ณด๋‚ด๋ฉด ์„œ๋ธ”๋ฆฟ์—์„œ ๋ฐ›์•„ ์ด๋ฅผ html๋กœ ์ถœ๋ ฅํ•œ๋‹ค.

- request.setCharacterEncoding("euc-kr");

jsp ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ ๋„˜๊ฒจ์ค„ ๋•Œ euc-kr๋กœ ๋„˜๊ฒจ์ฃผ๋„๋ก ์„ธํŒ…์ด ๋˜์–ด์žˆ์œผ๋ฏ€๋กœ ์ธ์ฝ”๋”ฉ ํƒ€์ž…์„ ๋งž์ถฐ์ค€๋‹ค.

- request.getParameter("name");

jsp ํŒŒ์ผ input ๋‚ด name ๊ฐ’์œผ๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

package servlet_test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Test")
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public Test() {
        super();
        // TODO Auto-generated constructor stub
    }
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("euc-kr");
		String name = request.getParameter("name");
		String age = request.getParameter("age");
		System.out.println("name: " + name + ", age: " + age);
		
		response.setContentType("text/html;charset=euc-kr");
		PrintWriter out = response.getWriter();
		out.println("<HTML>");
		out.println("<HEAD><TITLE>FORM</TITLE></HEAD>");
		out.println("<BODY>");
		out.println("์ด๋ฆ„์€ " + name + " ์ž…๋‹ˆ๋‹ค.");
		out.println("๋‚˜์ด๋Š” " + age + " ์ž…๋‹ˆ๋‹ค.");
		out.println("</BODY>");
		out.println("<HTML>");
		out.close();
		// doGet(request, response);
	}
}

 

โ‘ฅ ํ†ฐ์บฃ ๊ธฐ๋™ ํ›„ ๊ฒฐ๊ณผ ํ™•์ธ

default ํŒŒ์ผ์ด test.jsp์˜€๊ธฐ ๋•Œ๋ฌธ์— path ์ž…๋ ฅ ์—†์ด ์š”์ฒญ ์‹œ test.jsp ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค.

๊ฐ’ ์ž…๋ ฅ ํ›„ ์ „์†ก์„ ๋ˆ„๋ฅด๋ฉด action์— ์ž…๋ ฅ๋œ path๋ฅผ web.xml์—์„œ ์ฐพ์•„ ์„œ๋ธ”๋ฆฟ์„ ๋งคํ•‘์‹œํ‚จ๋‹ค.

 

POST ๋ฐฉ์‹์œผ๋กœ ์š”์ฒญ์ด ์™”์œผ๋ฏ€๋กœ doPost() ๋ฉ”์„œ๋“œ์— ์ •์˜๋œ ๋Œ€๋กœ ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

 

์„œ๋ธ”๋ฆฟ ์ƒ๋ช…์ฃผ๊ธฐ (Servlet LifeCycle)

Java EE(Java Enterprise Edition) ๊ธฐ๋ฐ˜ ํ”„๋กœ๊ทธ๋žจ์€ ์‹คํ–‰์˜ ํ๋ฆ„์„ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ œ์–ดํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  Servlet, JSP๋Š” Java EE์— ํฌํ•จ๋œ ํ•˜์œ„ ๊ธฐ์ˆ ์ด๋‹ค.

 

  1. ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๋Š” ํ•ด๋‹น ์„œ๋ธ”๋ฆฟ์ด ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ์—†์„ ๊ฒฝ์šฐ init() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌํ•œ๋‹ค.
  2. init()์ด ํ˜ธ์ถœ๋œ ํ›„ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋”ฐ๋ผ์„œ service() ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์ด doGet()๊ณผ doPost()๋กœ ๋ถ„๊ธฐ๋œ๋‹ค.
  3. ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์„œ๋ธ”๋ ›์— ์ข…๋ฃŒ ์š”์ฒญ์„ ํ•˜๋ฉด destroy() ๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค.
๋ฉ”์„œ๋“œ ๋ช… ์‹คํ–‰ ์‹œ์  ์‹คํ–‰ ํšŸ์ˆ˜ ์ž‘์—…
init() ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ์ตœ์ดˆ์˜ ์„œ๋ธ”๋ฆฟ ์š”์ฒญ์ด ์žˆ์„ ๋•Œ ์‹คํ–‰ 1 ์„œ๋ธ”๋ฆฟ ์ธ์Šคํ„ด์Šค ์ดˆ๊ธฐํ™”
service() ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์ด ์žˆ์„ ๋•Œ๋งˆ๋‹ค ์‹คํ–‰ n ์‚ฌ์šฉ์ž ์š”์ฒญ ์ฒ˜๋ฆฌ
destroy() ์„œ๋ธ”๋ฆฟ ๊ฐ์ฒด๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์‚ญ์ œ๋  ๋•Œ ์‹คํ–‰ 1 ์„œ๋ธ”๋ฆฟ ์†Œ๋ฉธ
๐Ÿ“š IoC(์ œ์–ด์˜ ์—ญํ–‰, Inversion of Control)
์‹คํ–‰์˜ ํ๋ฆ„์„ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ œ์–ดํ•˜์ง€ ์•Š๊ณ  ์ œ 3์ž๊ฐ€ ์ œ์–ดํ•˜๋Š” ๊ฒƒ์„ IoC๋ผ๊ณ  ํ•œ๋‹ค. Servlet๋„ IoC์— ์†ํ•œ๋‹ค.
๊ธฐ์กด ์ž๋ฐ” ๊ธฐ๋ฐ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์—์„œ๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ฐ์ฒด ๊ฐ„์˜ ์˜์กด๊ด€๊ณ„๋ฅผ ์†Œ์Šค๋กœ ํ‘œํ˜„ํ–ˆ๋‹ค.
์ด๋Ÿฐ ์ž‘์—…๋“ค์„ ์ปจํ…Œ์ด๋„ˆ๋กœ ์ฒ˜๋ฆฌํ•˜๋ฉด ์†Œ์Šค์—์„œ ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ์˜์กด๊ด€๊ณ„์— ๋Œ€ํ•œ ์ฝ”๋“œ ์—†์ด ๋‚ฎ์€ ๊ฒฐํ•ฉ๋„์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ (Servlet Container)

Servlet ํด๋ž˜์Šค์˜ ๊ทœ์น™์— ๋งž๊ฒŒ(์„œ๋ฒ„์— ๋งคํ•‘๋œ URL ์ •๋ณด์— ๋”ฐ๋ผ) ์„œ๋ธ”๋ฆฟ์„ ๋‹ด๊ณ  ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ์ปจํ…Œ์ด๋„ˆ์ด๋‹ค. 

  • HTTP ์š”์ฒญ์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ์ดˆ ์—ญํ• 
  • ์„œ๋ธ”๋ฆฟ์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  URL๊ณผ ํŠน์ • ์„œ๋ธ”๋ฆฟ์„ ๋งคํ•‘
  • ์š”์ฒญ๊ณผ ์‘๋‹ต ๊ฐ์ฒด ์ƒ์„ฑ ๋ฐ ๊ด€๋ฆฌ
  • Java EE ๋ช…์„ธ ์ค‘ Servlet API๋งŒ ๊ตฌํ˜„ํ•œ ๊ฒƒ
  • Java EE ์˜ ๋‹ค๋ฅธ ๊ธฐ์ˆ ์„ ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ์— ์‚ฌ์šฉํ•˜๋ ค๋ฉด classpath์— jar ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•จ

 

์ฐธ๊ณ ์ž๋ฃŒ ๋ฐ ์ถœ์ฒ˜ ๐Ÿ™‡‍โ™‚๏ธ

https://coding-factory.tistory.com/742

https://sallykim5087.tistory.com/121

https://lalwr.blogspot.com/2018/03/blog-post_20.html

https://ejolie.dev/posts/web-server-and-others

 

'๊ฐœ๋ฐœ > Spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Spring Boot ํ”„๋กœ์ ํŠธ git ์—ฐ๋™  (0) 2022.03.09
Spring Boot์— MySQL / Mybatis ์—ฐ๊ฒฐํ•˜๊ธฐ  (0) 2022.03.09
Spring Boot ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ  (0) 2022.03.08
JPA, Hibernate  (0) 2022.03.08
Spring Security  (0) 2022.03.07

๋Œ“๊ธ€