JSP

includeTestForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>

<!-- includeTestForm.jsp -->

<form method="post" action="includeTest.jsp">
 
 이름 <input name="name"><br>

 포함할 페이지 <input name="pageName" value="includedTest.jsp" >
 <br>
 <input type="submit" value="전송">
</form>



</body>
</html>

 

 

 

 

includeTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>


<!-- includeTest.jsp -->
<!-- param.name => request.getParameter("name")  -->
<!-- EL(Expression Language, 표현언어) -->


<%
	//한글 인코딩 설정(post 방식)
	request.setCharacterEncoding("utf-8");
%>


<%-- jsp 액션 태그, <jsp:include 페이지를 링크시킴  --%>
<%-- <jsp:include page="includedTest.jsp"></jsp:include> --%>

<%@ include file="includedTest.jsp" %>

<%-- <jsp:include>액션태그 2개의 클래스로 컴파일, 변수공유가 안됨

<%@ include %> 1개의 클래스로 컴파일, 변수공유 가능  --%>



이름 : <%= request.getParameter("name") %> <br>
페이지 이름 : <%= request.getParameter("pageName") %> <br>



이름 :${param.name } <br>
페이지 이름 : ${param.pageName } <br>



</body>
</html>

 

 

 

includedTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

    

페이지 includeTest 페이지 입니다.

<hr>   

 

이름 
포함할 페이지  

 

 

=>

 

 

페이지 includeTest 페이지 입니다.

이름 : 홍길동 
페이지 이름 : includedTest.jsp 
이름 :홍길동 
페이지 이름 : includedTest.jsp 

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

여간 채소를 먹으며 서로 사랑하는 것이 살찐 소를 먹으며 서로 다투는 것보다 나으리라. -잠언

댓글 ( 4)

댓글 남기기

작성