5.1 ํฌํจ
์ ๊ฐ ์ด์ผ๊ธฐํ๊ณ ์ถ์ ๋ง๋ฒ ์ง์๋ฌธ์ด ๋ช ๊ฐ์ง ๋ ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ์ง์๋ฌธ์ include ์ง์๋ฌธ์ ๋๋ค . ํ์๋ ํ์ด์ง ์์น์ ๋ค๋ฅธ ํ์ผ์ ์ฝ์ ํ ์ ์์ต๋๋ค. ์ด๋ฌํ ์ง์๋ฌธ์ ์ผ๋ฐ์ ์ธ ํ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
<%@ include file="url"%>
ํ์ผ๋ฟ๋ง ์๋๋ผ ์๋ฅผ ๋ค์ด ๋ค๋ฅธ jsp-servlet ๋๋ URL์ ์ง์ ํ ์ ์์ต๋๋ค.
์:
<%@ include file="header.jsp"%>
<%
double num = Math.random();
if (num > 0.95) {
out.print(num);
}
%>
<%@ include file="footer.jsp"%>
์๋ฅผ ๋ค์ด ์ฌ์ดํธ์ ๋ชจ๋ ํ์ด์ง์ ์๋จ ๋ถ๋ถ์ header.jsp์, ํ๋จ ๋ถ๋ถ์ footer.jsp์ ๋ฃ๊ณ ๋ชจ๋ ํ์ด์ง๋ฅผ ์์ฑ์๋ก ์์งํ ์ ์์ต๋๋ค.
5.2 ํฌ์๋
ํด๋์ ์๋ธ๋ฆฟ์๋ ๋ค๋ฅธ URL๋ก ๋ฆฌ๋๋ ์ ํ๊ฑฐ๋ ์ ๋ฌํ ์ ์๋ ๊ธฐ๋ฅ์ด ์๋ค๋ ๊ฒ์ ๊ธฐ์ตํ์ญ๋๊น ? JSP์์๋ ์ด๊ฒ๋ ๊ฐ๋ฅํ๋ฉฐ ์ด์ ๋ํ ํน๋ณ ์กฐ์น๊ฐ ์์ต๋๋ค. ์ด์ ์ ๋ณธ ๊ฒ๊ณผ ๋ชจ์์ด ์ฝ๊ฐ ๋ค๋ฆ ๋๋ค.
<jsp:forward page="url"/>
๋ค์๊ณผ ๊ฐ์ ๋งค๊ฐ๋ณ์๊ฐ ํฌํจ๋ ๊ณ ๊ธ ์ต์ ๋ ์์ต๋๋ค.
<jsp:forward page="url" >
<jsp:param name="Name" value="meaning"/>
<jsp:param name="Name" value="meaning"/>
<jsp:param name="Name" value="meaning"/>
</jsp:forward>
์:
<html>
<head>
<title>The Forward Example</title>
</head>
<body>
<center>
<h2> Forward example </h2>
<jsp:forward page="login.jsp"/>
</center>
</body>
</html>
5.3 ๋ฆฌ๋๋ ์
๋ฆฌ๋๋ ์ ์ ๋ํ ํน๋ณํ ์ง์๋ฌธ์ ์์ง๋ง Java ์ฝ๋๋ฅผ ํธ์ถํ์ฌ ์ํํ ์ ์์ต๋๋ค.
์:
<body>
<%
String redirectURL = "https://codegym.cc/";
response.sendRedirect(redirectURL);
%>
</body>
302
์ด ์๋ ๋ฆฌ๋๋ ์
์ ๋ณด๋
๋๋ค . ๋ฆฌ๋๋ ์
์ด ํ์ํ ๊ฒฝ์ฐ 301
๋ช ์ค์ ์ฝ๋๋ฅผ ๋ ์์ฑํด์ผ ํฉ๋๋ค.
<body>
<%
response.setStatus(301);
response.setHeader("Location", "https://codegym.cc/");
response.setHeader("Connection", "close");
%>
</body>
GO TO FULL VERSION