반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

비전공개미 개발노트

[JSP] jsp:forward를 사용해 페이지 불러오기 본문

프로그래밍/JSP

[JSP] jsp:forward를 사용해 페이지 불러오기

비전공개미 2022. 10. 11. 19:04
반응형
SMALL

ex14.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>
<form action="ex15.jsp" method="post">
	이동하고 싶은 페이지 <input type="text" name="p" >
	<input type="submit" value="이동">
</form>

</body>
</html>

 

이동하고 싶은 페이지 : input에 페이지명을 입력

hello입력

 

 

ex15.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 p = request.getParameter("p");
p = p + ".jsp";
%>
<jsp:forward page="<%=p %>" />
</body>
</html>

 

request.getParameter로 값을 받아와서 변수 p에 저장

p값에 ".jsp"값을 붙인다.

 

<jsp:forward page="<%=p%>" />

jsp:forward page값을 넣어주고

hello.jsp파일로 이동

 

hello.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>
<h1>Hello!</h1>
</body>
</html>

 

hello.jsp파일의 내용이 출력된다

 

Insert title here

Hello!

반응형
LIST
Comments