CodeGym /Java Course /๋ชจ๋“ˆ 3 /JSP ๋Œ€ HTML ์ฃผ์„

JSP ๋Œ€ HTML ์ฃผ์„

๋ชจ๋“ˆ 3
๋ ˆ๋ฒจ 13 , ๋ ˆ์Šจ 3
์‚ฌ์šฉ ๊ฐ€๋Šฅ

๋˜ ๋‹ค๋ฅธ ์ค‘์š”ํ•œ ์ ์€ JSP์˜ ์ฃผ์„์ž…๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค์—์„œ๋Š” ํ•ญ์ƒ ์ฝ”๋“œ๋ฅผ ์ƒ์‚ฐ์— ๋“ค์–ด๊ฐ„ ํ›„ ์ง€์›ํ•ด ์ค„ ์šฉ๊ฐํ•œ ์‚ฌ๋žŒ๋“ค์„ ์œ„ํ•ด ๋ฌด์–ธ๊ฐ€๋ฅผ ์ฃผ์„ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋‚จ๊ฒจ ๋‘˜ ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

JSP ๋‚ด๋ถ€์˜ ์ฝ”๋“œ๋ฅผ ์ฃผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์€ ๋งค์šฐ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” ํŠน์ˆ˜ "๋Œ€๊ด„ํ˜ธ"๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

<%-- a comment --%>

์ด๋Ÿฌํ•œ ๋Œ€๊ด„ํ˜ธ ์•ˆ์˜ ๋ชจ๋“  ์ฝ”๋“œ๋Š” JSP๋ฅผ ์„œ๋ธ”๋ฆฟ์œผ๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ์ด ์ฝ”๋“œ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์€ HTML ์ฃผ์„๊ณผ ํ˜ผ๋™ํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค.

<!-- HTML comment _ -->

์ฝ”๋“œ์—์„œ HTML ์ฃผ์„์„ ์—‰๋ง์œผ๋กœ ์‚ฌ์šฉํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


    <html> 
    <body>   <!--
    <%
        double num = Math.random();
        if (num > 0.95) {
            out.print(num);
        }
    %>  -->
    </body> 
</html> 

๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

public class HelloServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)  throws Exception {
    PrintWriter out = resp.getWriter();
    out.print("<html> ");
    out.print("<body> <--");
        double num = Math.random();
        if (num > 0.95) {
             out.print(num);
        }
    out.print("-->");
    out.print("</body>");
    out.print("</html>");
    }
}

HTML ์ฝ”๋“œ๋Š” ์ฃผ์„ ์ฒ˜๋ฆฌ๋˜์ง€๋งŒ ํ•ด๋‹น ์ฃผ์„ ๋‚ด์˜ Java ์ฝ”๋“œ๋Š” ๊ณ„์† ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋ฉ˜ํŠธ
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION