JSP & Servlet
๐ถ๋ณํํ๋ฆ
JSP => Servlet(.java) => Class
Servlet
- ๋น์ง๋์ค ๋ก์ง์ฉ (if๋ฌธ,for๋ฌธ)
- ๋ณต์กํ ๋ก์ง ๊ตฌํ์ ์ ํฉํ๋Java์์ฃผ์ ์์ฑ๋ฐฉ์์ด๊ธฐ ๋๋ฌธ์ ํ๋ฉด๊ตฌํ ์ ์ด๋ ค์์ด ์กด์ฌJSP
- ํ๋ฉด๊ตฌํ์ฉ
- ์๋ฐ ๋ด์ HTML์ฝ๋๊ฐ ์์
- ํ๋ฉด๊ตฌ์ฑ์ ์ฉ์ํ๋ ์์ค๊ฐ ๊ณต๊ฐ๋ ๋จ์ ์ด ์กด์ฌ
๐ถ ๊ตฌ์ฑ์์
โป 1. ์ง์์
- ์๋ฐ๋ด์ ํ์ํ๊ฒ์ ๊ธฐ์ ํ๊ธฐ์ํ ๊ตฌ์ฑ์์
- ํ์ด์ง ์ง์์ :
- ํ๊ฒฝ์ค์ ex) import
<%@page errorPage="ex04ErrorPage.jsp"%>
- include ์ง์์ :
- ํค๋ ํธํฐ ๋ฑ ์ปดํฌ๋ํธ๋ฅผ ๋ถ๋ฌ์ฌ๋ ์ฌ์ฉ
<%@include file='ex05Footer.jsp' %>
- taglib(ํ๊ทธ๋ผ์ด๋ธ๋ฌ๋ฆฌ) ์ง์์ :
- jstl ๋ผ์ด๋ธ๋ฌ๋ฆฌ
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
โป 2. ์ ์ธ๋ฌธ(Declaration)<c:forEach begin="1" end="3" step="1"> <h1>hello world222!</h1> </c:forEach
- ์ ์ญ๋ณ์
<%! %>
โป 3. ์คํฌ๋ฆฝํธ์(Scriptlet)- JSP๋ด์์ ์๋ฐ์ฝ๋๋ฅผ ์ธ์์๊ฒ ํ๋ ๊ธฐ๋ฅ
<% %>
- HTML์ฃผ์ ๋ด์์ ๊ตฌ์ฑ์์ ์์ฑํ๋ฉด ์๋จ (์ฃผ์๋ด์์๋ ์ธ์๋จ)
โป 4. ํํ์(expression) - ์ ์ธํ๋ณ์, ๋ฉ์๋๋ฅผ ํธ์ถํ ๋ ์ฌ์ฉ๋๋ ๊ธฐ๋ฅ
<%= %>
<body>
<div class="wrap" style="margin:auto">
<!-- ์ ์ญ์ค์ -->
<%! int num2 = 100;%>
<%int num = 10; %>
<!-- if -->
<%if(num %2 == 0){%>
<h1>โ ์ง์ ์
๋๋ค โ</h1>
<% }%>
<!-- if -->
<%= num%>
<%= num2 %>
</div>
</body>
EL์ (Expression Language)
---> ${์๋ฐ์ฝ๋}
์์ :
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<body>
<c:choose>
<c:when test="${num % 2 == 0}">
<h1>If you can see this sentence, It might be even number</h1>
</c:when>
<c:when test="${num % 2 == 1}">
<h1>If you can see this sentence, It might be odd number</h1>
</c:when>
<c:otherwise>
<h1>If you can see this sentence, something is wrong with this program</h1>
</c:otherwise>
</c:choose>
</body>
'โ Web > Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
7. Spring Boot ๊ฒ์ํย ์์ฑ(2) (1) | 2025.06.04 |
---|---|
5. Spring Boot WorkSpace ์ค์ ๋ฐฉ๋ฒ(๊ธฐ๋ณธ์์) (0) | 2025.05.29 |
4. SpringBoot ๊ธฐ๋ณธ๊ธฐ๋ฅ ์๊ฐ (1) | 2025.05.29 |
2. ์๋ธ๋ฆฟ ํ๊ฒฝ์ค์ (์ดํด๋ฆฝ์คํ๊ฒฝ , ์คํ๋ง x) (0) | 2025.05.09 |
1. ์คํ๋ง ์๊ฐ (1) | 2025.05.09 |