2023. 2. 10. 10:23ใJSP&Servlet
servlet์ ๋ง๋ค๋ฉด ํด๋์ค๋ก ๋ง๋ค์ด์ง๋ฉฐ, HttpServlet ํด๋์ค๋ฅผ ์์ ๋ฐ๋๋ค.
HttpServlet์ ์น๊ฐ๋ฐ์ ํ์ํ ๋ชจ๋ ๊ธฐ๋ฅ์ด ์ ์๋์ด ์๋ค.
๋ฐ๋ผ์ ์น ๊ฐ๋ฐ ๊ธฐ๋ฅ์ ์์ ๋ฐ์ ์ธ ์ ์๋ค.
HttpServlet์ ์์ ๋ฐ์ ๋ง๋ ํด๋์ค๋ฅผ Servlet์ด๋ผ ํจ!
Servlet์ ์คํ์ํค๋ฉด ํฐ์บฃ์ด main ๋ฉ์๋๋ฅผ ์๋์ผ๋ก ๊ตฌ๋์์ผ์ค๋ค.
main ๋ฉ์๋๊ฐ ์คํ๋๋ฉด doGet() ๋ฉ์๋๋ doPost()๋ฉ์๋ ์ค ํ๋๊ฐ ๋ฌด์กฐ๊ฑด ์คํ๋๋ค. (๋๊ฐ ๋ค ์คํ x)
์๋ฐ๋ ๋ฉ์ธ ๋ฉ์๋๊ฐ ์์ผ๋ฉด ์คํ ์๋์ง๋ง, ์น ๊ฐ๋ฐ์ W.A.S์ธ ํฐํท์ด ๊ทธ ๊ธฐ๋ฅ์ ๋์ ํ์ฌ ์คํ์์ผ์ฃผ๋ ๊ฒ.
http : ํ๋กํ ์ฝ์ ํ ์ข ๋ฅ (์ปดํจํฐ๊ฐ์ ํต์ ํ๋ ๋ฐฉ๋ฒ ์ค ํ๋)
์คํ๋ ์ฃผ์ - http://localhost:8081/ServletProject/FirstServlet
๋ด์ปดํจํฐ : 8081 ์ฌ์ฉํ๋ ํฐ์บฃ์ ์ ์ / ์ฐ๋ฆฌ๊ฐ ์คํ์ํจ ํ๋ก์ ํธ๋ช / ํด๋์ค๋ช
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
//HttpServlet ํด๋์ค์๋ ์น ๊ฐ๋ฐ์ ํ์ํ ๊ธฐ๋ฅ์ด ์ ์๋์ด ์๋ค.
//๊ทธ๋์ ํด๋์ค๋ฅผ ๋ง๋ค ๋ HttpServlet ํด๋์ค๋ฅผ ์์ํ๋ฉด
//HttpServlet ํด๋์ค์ ์ ์๋ ์น ๊ฐ๋ฐ์ ํ์ํ ๊ธฐ๋ฅ์ ์์ ๋ฐ์ ์ธ ์ ์๋ค.
//์ด๋ ๊ฒ ์น ๊ฐ๋ฐ์ ํ์ํ ๊ธฐ๋ฅ์ ์ ์ํ HttpServletํด๋์ค๋ฅผ ์์ ๋ฐ์ ๋ง๋
//ํด๋์ค๋ฅผ Servlet์ด๋ผ ์ง์นญํ๋ค.
//Servlet์ ์คํ์ํค๋ฉด ํฐ์บฃ์ด main ๋ฉ์๋๋ฅผ ์๋์ผ๋ก ๊ตฌ๋์์ผ์ค๋ค.
//main ๋ฉ์๋๊ฐ ์คํ๋๋ฉด doGet() ๋ฉ์๋๋ doPost()๋ฉ์๋ ์ค ํ๋๊ฐ ๋ฌด์กฐ๊ฑด ์คํ๋๋ค.
public class FirstServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
//์์ฑ์
public FirstServlet() {
super();
}
//HttpServlet ํด๋์ค์ ๋ฉ์๋ ์ค๋ฒ๋ผ์ด๋ฉ ๋ ๊ฒ.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doGet() ๋ฉ์๋ ์คํ");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doPost() ๋ฉ์๋ ์คํ");
}
}
'JSP&Servlet' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๋ฐ์ดํฐ ์ ๋ฌํ๊ธฐ (aํ๊ทธ) (0) | 2023.02.13 |
|---|---|
| ๋ฐ์ดํฐ ๋๊ธฐ๊ธฐ ์ค์ต(form) (0) | 2023.02.13 |
| โ โ โ JSP ๋ค๋ฅธ ํ์ด์ง๋ก ๋ฐ์ดํฐ ๋๊ธฐ๊ธฐ (form) (0) | 2023.02.10 |
| JSP (0) | 2023.02.10 |
| servlet / jsp ๊ธฐ์ด (0) | 2023.02.10 |