반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

비전공개미 개발노트

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

프로그래밍/JSP

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

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

includeName.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="includeTag.jsp" action="post">
	이름 : <input type="text" name="name"><br><br>
	<input type="submit" value="보내기">
</form>
</body>
</html>

 

이름의 input값에 값을 적고 includeTag.jsp로 submit한다

name == 고난

 

 

includeTag.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.setCharacterEncoding("utf-8");
String name = "장미장미";
%>
<jsp:include page="includeTagTop.jsp" />
include ActionTag의 Body임<br>
</body>
</html>

 

jsp:include를 통해 includeTagTop.jsp파일을 불러온다

 

 

includeTagTop.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 name = request.getParameter("name"); //name을 parameter값으로 받아옴
//forward 또는 include시 request값을 없애지 않고 가져간다
%>
include ActionTag의 Top임
<p>
<h1>내 이름은 <%=name %>. 탐정이죠!!</h1>
<hr>
</body>
</html>

 

request.getParameter로 name값을 받아와 변수 name에 저장하고 <%=name%>을 출력한다.

 

 

 

[출력]

 

Insert title here include ActionTag의 Top임

내 이름은 고난. 탐정이죠!!


include ActionTag의 Body임
반응형
LIST
Comments