11redirect.jsp์ ์ฝ๋๋ด์ฉ
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
๋๋ ๋ฆฌ๋ค์ด๋ ํธ ์ ํ์ด์ง
<%
String name="์ฐฝ๋ฏผ";
String encodedName = URLEncoder.encode(name, "utf-8");
response.sendRedirect("11redirectPage.jsp?name=" + encodedName); // ํฌ๋กฌ์, ๋ ์ฃผ์ด์ง ์ฃผ์๋ก ๋ค์ํ๋ฒ ์์ฒญํด๋ผ
%>
<!--
์์ด๋ :
๋น๋ฐ๋ฒํธ :
๋ก๊ทธ์ธ(loginCheck.jsp) ํ์๊ฐ์
loginCheck.jsp ๋ด์ฉ์ ์์ด๋, ๋น๋ฐ๋ฒํธ ํ์ธํ๋ ๋ด์ฉ
if(๋ก๊ทธ์ธ์ฑ๊ณต){
redirect ํ ํ๋ฉด
}
-->
</body>
</html>
11redirectPage.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%=request.getParameter("name")%>
</body>
</html>
redirect๋ 2๋ฒ ์์ฒญํ๋ค. ๋ฌด์จ๋ง์ด๋๋ฉด
์ ์ฝ๋์ ๊ฒฝ์ฐ url์์ฒญ์ http://localhost:8080/study/01basic/11redirect.jsp?name=์ฐฝ๋ฏผ ์ผ๋ก ์ ๊ทผ์
url์ http://localhost:8080/study/01basic/11redirectPage.jsp?name=์ฐฝ๋ฏผ ์ผ๋ก ๋ฐ๋๋ค.
์?
11redirect.jsp๋ฅผ ๋ณด๋ฉด response.sendRedirect("11redirectPage.jsp?name=" + encodedName); ๋ฅผ ํตํด์ ๋ค์ํ๋ฒ ์์ฒญํ๋๋ก ๋์ด์๊ธฐ ๋๋ฌธ์ด๋ค. ๊ทธ๋ฆฌ๊ณ 11redirectPage.jsp์์๋ request.getParameter("name") ๋ฅผ ์ฌ์ฉํด์ ํ๋ผ๋ฏธํฐ๊ฐ์ ๊ฐ๊ณ ์ค๊ธฐ ๋๋ฌธ์ ๊ฒฐ๊ณผ์ ์ผ๋ก url์ด ๋ณ๊ฒฝ๋๋ค.
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Day02(declaration)์ ์ธ์ ! (0) | 2021.10.05 |
---|---|
Day02(servlet, jsp) (0) | 2021.10.05 |
Day02(aboutRequest) (0) | 2021.10.05 |
Day01(ํ์ ๋ณํ) (0) | 2021.10.05 |
Day01(img) (0) | 2021.10.05 |