프로그래밍/JSP
[JSP] get.Parameter값을 받아와서 페이지 바꾸기
비전공개미
2022. 10. 12. 19:32
반응형
SMALL
home.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>
<%String target = request.getParameter("target"); %>
<p>소환사의 협곡에 오신 것을 환영합니다.</p>
<img src="images/lol.jpg" alt="롤이미지"/>
</body>
</html>
tech.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>
<img src="images/1.png" alt="weapon" />
<img src="images/2.png" alt="weapon" />
<img src="images/3.png" alt="weapon" />
<img src="images/4.png" alt="weapon" />
</body>
</html>
champ.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>
<img src="images/1.jpg" alt="champ" />
<img src="images/2.jpg" alt="champ" />
<img src="images/3.jpg" alt="champ" />
<img src="images/4.jpg" alt="champ" />
<img src="images/5.jpg" alt="champ" />
<img src="images/6.jpg" alt="champ" />
<img src="images/7.jpg" alt="champ" />
<img src="images/8.jpg" alt="champ" />
</body>
</html>
index.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로 target값을 get으로 받아온 후 .jsp를 붙여서 target변수에 저장 -->
<%String target = request.getParameter("target")+".jsp"; %>
<table border="1">
<tr>
<td colspan="2"><jsp:include page="include/top.jsp" flush="false" /></td>
</tr>
<tr>
<td valign="top" style="padding-right:1em;"><jsp:include page="include/menu.jsp" flush="false"/></td>
<td>
<!-- target값이 바뀔때마다 다른 페이지를 include해온다 -->
<jsp:include page="<%=target %>" flush="false" />
</td>
</tr>
<tr>
<td colspan="2"><jsp:include page="include/bottom.jsp" flush="false" /></td>
</tr>
</table>
</body>
</html>
method = "GET" 방식은 POST방식과는 다르게 url에 파라미터 값이 표시되어서 온다.
ex) index.jsp?target=champ
target값은 champ라는 값을 가져오며
request.getParameter("target");로 target의 value값 = champ를 가져올 수 있다.
중복값일경우
ex) index.jsp?target=champ&game=lol
&(ampersand)를 기준으로 여러개의 값을 가져올 수 있다.
target의 값은 champ
game의 값은 lol
반응형
LIST