๐Ÿ“„ Servlet & JSP ไธ‹

๐Ÿ“ฎ Servlet & JSP

URLMapping

์ฒซ๋ฒˆ์งธ web.xml์˜ <servlet>๋ธ”๋ก๊ณผ <servlet-mapping>๋ธ”๋ก์„ ํ†ตํ•ด ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ ๋‘๋ฒˆ์งธ Servlet ํด๋ž˜์Šค ๊ฐ์ฒด์— @WebServlet("/example") ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ด ๋งคํ•‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

โœ”๏ธ ๋™์‹œ์— ๋‘ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์—๋Ÿฌ

DefaultServlet

web.xml์—๋Š” ์ง€์ •ํ•œ <servlet>๋ธ”๋ก์—์„œ mapping๋˜์ง€ ์•Š์€ staticํ•œ ๋ฆฌ์†Œ์Šค๋“ค์ด๋‚˜ url๋กœ์˜ ์ ‘๊ทผ์€ ๋‚ด๋ถ€์ ์œผ๋กœ ์ •์˜๋˜์–ด์žˆ๋Š” DefaultServlet์— ์˜ํ•ด / ๋กœ ์ „๋‹ฌ๋œ๋‹ค.

๐Ÿ’ฒ JSTL

๐Ÿ“š JSTL Library

Core (prefix:c)

๋ณ€์ˆ˜์„ ์–ธ, ์‹คํ–‰ํ๋ฆ„์˜ ์ œ์–ด, ํŽ˜์ด์ง€ ์ด๋™

Formatting (prefix:fmt)

์ˆซ์ž, ๋‚ ์งœ, ์‹œ๊ฐ„๋“ฑ์˜ ํฌ๋งคํŒ… ๊ธฐ๋Šฅ

Function (prefix:fn)

๋ฌธ์ž์—ด ํ•จ์ˆ˜ ์ œ๊ณต

๐Ÿ’ฌ ๋ฌธ๋ฒ•

  • <c:choose> : if ~ else if ~ else

    • ์„œ๋ธŒํƒœ๊ทธ๋กœ <c:when>๊ณผ <c:otherwise>
    • test ์กฐ๊ฑด์—์„œ ์ง€์ •ํ•œ ์งˆ์˜๋ฅผ ํŒ๋ณ„
  • <c:forEach>

    • items ๋กœ iterateํ•  ๊ฐ์ฒด๋ฅผ ์ •ํ•˜๊ณ 
    • iterateํ•˜๋Š” ๊ฐ๊ฐ์˜ index ๊ฐ์ฒด๋ฅผ var ๋กœ ์ง€์ •
    • varStatus ๋Š” ๊ณผ์ • ์†์˜ index๊ฐ’
    • step ์ฆ๊ฐํ•˜๋Š” ๊ฐ’
  • <c:set> : ๋ณ€์ˆ˜์— ๊ฐ’์„ ์„ค์ •

  • <c:import> : ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋ฅผ ๋™์ ์œผ๋กœ ํฌํ•จ์‹œํ‚ฌ๋•Œ ์‚ฌ์šฉ

<c:import url="url">
   <c:param name="๋ณ€์ˆ˜์ด๋ฆ„" value="๊ฐ’"></c:param>   	
</c:import>

๐Ÿ”ญ Scope ์šฐ์„ ์ˆœ์œ„

graph LR
 A[PageScope] --> B[RequestScope]
 B[RequestScope] --> C[SessionScope]
 C[SessionScope] --> D[ApplicationScope]

๋‹ค๋ฅธ JSP ๋ฌธ์„œ ์ฐธ์กฐํ•˜๊ธฐ

<jsp:include page="/WEB-INF/views/include/navigation.jsp" />
<c:import url="url">
   <c:param name="๋ณ€์ˆ˜์ด๋ฆ„" value="๊ฐ’"></c:param>   	
</c:import>