๐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");
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 ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด๋ด๋ ๋ฐ ์ข ๋ ํนํ๋ ๊ธฐ์ ์.