JSP๋ž€?

BaeSeBinยท2024๋…„ 12์›” 24์ผ
0

JSP

๋ชฉ๋ก ๋ณด๊ธฐ
1/3

๐Ÿ˜ŠJSP๋ž€?

JAVA SERVER PAGE์˜ ์•ฝ์ž๋กœ ์„œ๋ธ”๋ฆฟ(Servlet)๊ธฐ์ˆ ๊ณผ ๋™์ผํ•˜๊ฒŒ ์„œ๋ฒ„์—์„œ ๋™์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค.

JSP vs Servlet

๋‘ ๊ธฐ์ˆ ์˜ ๋ชฉ์ ์ด ๋‹ค๋ฆ„
JSP ๊ธฐ์ˆ ์€ Servlet๊ณผ ๋‹ฌ๋ฆฌ HTML์ฝ”๋“œ๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์•ฝ๊ฐ„์˜ ์ž๋ฐ” ์ฝ”๋“œ๋ฅผ ์‚ฝ์ž…ํ•˜๋Š” ๋ฐฉ์‹์ž„
ex) JSP ์ฝ”๋“œ
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>
<h1><%= "Hello World!" %>
</h1>
<h1><%= "Hello World!" %>
</h1>
<br/>
<a href="hello-servlet">Hello Servlet</a>
</body>
</html>
ex) Servlet ์ฝ”๋“œ
package com.zeorck.web_application;

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("<h1>" + message + "</h1>");
        out.println("<h1>" + message + "</h1>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }

    public void destroy() {
    }
}
JSP ์ฝ”๋“œ๋Š” ์ž๋ฐ” ์ฝ”๋“œ๊ฐ€ ์•„๋‹ˆ์ง€๋งŒ Servlet๊ณผ ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌ๋จ
"JSPํŒŒ์ผ๋„ Servlet ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜๋˜์–ด์„œ ์ปดํŒŒ์ผ๋˜๊ณ  ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์ž„"
JSP๋Š” Servlet๋ณด๋‹ค ๋ธŒ๋ผ์šฐ์ €์— ๋ณด๋‚ด๋Š” HTML ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด๋‚ด๋Š” ๋ฐ ์ข€ ๋” ํŠนํ™”๋œ ๊ธฐ์ˆ ์ž„.

0๊ฐœ์˜ ๋Œ“๊ธ€