JAVA

application ๊ฐ์ฒด?

์„œ์œค-์ • 2023. 11. 28. 11:04

๐Ÿ’œapplication ๊ฐ์ฒด

Java ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ชจ๋“  ์‚ฌ์šฉ์ž ๊ฐ„์— ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ์ฒด์ด๋‹ค.

์ด ๊ฐ์ฒด๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์„œ๋ฒ„์— ๋ฐฐํฌ๋  ๋•Œ ์ƒ์„ฑ๋˜์–ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ ์‚ด์•„์žˆ๋‹ค.

๊ฐ ์‚ฌ์šฉ์ž์˜ ์„ธ์…˜๊ณผ๋Š” ๋‹ฌ๋ฆฌ, application ๊ฐ์ฒด๋Š” ๋ชจ๋“  ์„ธ์…˜์—์„œ ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š”๋ฐ ์ ํ•ฉํ•˜๋‹ค.

 

์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ „์—ญ์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ์ปจํ…์ŠคํŠธ(์ปจํ…์ŠคํŠธ๋Š” ์„œ๋ธ”๋ฆฟ ๋ฐ JSP์—์„œ ์‹คํ–‰๋˜๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ผ์ข…์˜ ์ปจํ…Œ์ด๋„ˆ) ๊ฐ์ฒด์ด๋‹ค.

์ด๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž ๊ฐ„์— ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๊ฑฐ๋‚˜ ์ „์—ญ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฃผ์š” ํŠน์ง•๊ณผ ์‚ฌ์šฉ ์˜ˆ์‹œ:

1) ๋ฐ์ดํ„ฐ ๊ณต์œ : application ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  ์‚ฌ์šฉ์ž๊ฐ€ ๊ณตํ†ต์ ์œผ๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.

2) ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ˆ˜์ค€์˜ ์ดˆ๊ธฐํ™”: ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹œ์ž‘๋  ๋•Œ application ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ดˆ๊ธฐํ™” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. 

3) ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ: ์„œ๋ธ”๋ฆฟ ์ปจํ…์ŠคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ํ†ตํ•ด application ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ํŠน์ • ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๋ฐ˜์‘์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

4) ์„ธ์…˜๊ณผ์˜ ์ฐจ์ด: application ๊ฐ์ฒด๋Š” ๋ชจ๋“  ์„ธ์…˜์—์„œ ๊ณต์œ ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋ฉฐ, ๊ฐ ์„ธ์…˜๋งˆ๋‹ค ๊ณ ์œ ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” session ๊ฐ์ฒด์™€ ๊ตฌ๋ณ„๋œ๋‹ค.

 

 

 

 

 

๐Ÿ’› ์˜ˆ์‹œ

1) ๋ฐฉ๋ฌธ์ž ์ˆ˜ ์ถ”์  (visitCount.jsp)

<%@ page contentType="text/html" pageEncoding="utf-8" %>
<%
    String strcnt = (String) application.getAttribute("counter");
    int count = (strcnt == null) ? 0 : Integer.valueOf(strcnt);
    out.print("๋ฐฉ๋ฌธ์ž์ˆ˜: " + count);
    application.setAttribute("counter", String.valueOf(++count));
%>

-- ์‚ฌ์šฉ์ž๊ฐ€ ํŽ˜์ด์ง€๋ฅผ ๋ฐฉ๋ฌธํ•  ๋•Œ๋งˆ๋‹ค application ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฉ๋ฌธ์ž ์ˆ˜๋ฅผ ์ฆ๊ฐ€์‹œํ‚ค๊ณ ,

ํ•ด๋‹น ํŽ˜์ด์ง€ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

 

2) ์›น ํŽ˜์ด์ง€์—์„œ ๋ฐฉ๋ฌธ์ž ์ˆ˜ ํ‘œ์‹œ (index.jsp)

<%@ page contentType="text/html" pageEncoding="utf-8" %>
<html>
<head>
    <title>๋ฐฉ๋ฌธ์ž ์ˆ˜ ํ‘œ์‹œ ํŽ˜์ด์ง€</title>
</head>
<body>
    <h2>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!</h2>
    <%@ include file="visitCount.jsp" %>
</body>
</html>

-- ์ด ํŽ˜์ด์ง€์—์„œ๋Š” visitCount.jsp๋ฅผ includeํ•˜์—ฌ ๋ฐฉ๋ฌธ์ž ์ˆ˜๋ฅผ ํ‘œ์‹œํ•œ๋‹ค.

์ด ํŽ˜์ด์ง€๋ฅผ ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋ฐฉ๋ฌธํ•ด๋„ application ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ๋ฐฉ๋ฌธ์ž ์ˆ˜๊ฐ€ ์ •ํ™•ํ•˜๊ฒŒ ์ถ”์ ๋œ๋‹ค.

 

 

3) ์›น ํŽ˜์ด์ง€์—์„œ ํŠน์ • ์ผ์ž ์ฒดํฌ (checkDate.jsp)

<%@ page contentType="text/html" pageEncoding="utf-8" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
    Date now = new Date();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String date = df.format(now);

    if (date.endsWith("12")) {
        response.sendRedirect("underCheck.jsp");
        return;
    }

    String uid = request.getParameter("id");
    String res = "<h3>์‚ฌ์šฉ์ž ์•„์ด๋””: " + uid + "</h3>";
    res += "<br>๋กœ๊ทธ์ธ ์‹œ๊ฐ„: " + now.toString();
    out.print(res);
%>
<br><br>
<%@ include file="visitCount.jsp" %>

-- ์ด ํŽ˜์ด์ง€์—์„œ๋Š” ํ˜„์žฌ ๋‚ ์งœ๋ฅผ ํ™•์ธํ•˜๊ณ , ๋งŒ์•ฝ ๋‚ ์งœ๊ฐ€ 12๋กœ ๋๋‚œ๋‹ค๋ฉด ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰์…˜ํ•œ๋‹ค.

๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” ์‚ฌ์šฉ์ž ์•„์ด๋””์™€ ํ˜„์žฌ ๋กœ๊ทธ์ธ ์‹œ๊ฐ„์„ ์ถœ๋ ฅํ•œ๋‹ค.