728x90
지시자
화면을 제작할 때 레이아웃 구성시(지시자)<%@include> 서블릿이 include 시킨 갯수 상관없이 1개.
즉 addr을 바로 사용가능
-top.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@page import="java.util.Date"%> <%@ 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>top.jsp입니다.</title> </head> <body> <h1>top.jsp입니다.</h1> <%=new Date().toLocaleString()%> </body> </html> | cs |
-footer.jsp
1 2 3 4 5 6 7 8 9 10 11 12 | <%@ 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> </head> <body> <h3>주소 : <%=addr%></h3> </body> </html> | cs |
-index.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <%@ 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> </head> <body> <h1>include 지시자</h1> <% String addr = "제주도";%> <%@ include file="top.jsp" %> <hr /> 여기는 index.jsp문서입니다. <hr color="red" /> <%@ include file="footer.jsp" %> </body> </html> | cs |
액션태그
<jsp:include> 서블릿이 include 시킨 개수만큼 생성됨.
즉 변수 addr을 바로 사용불가 3개의 페이지로 나뉘기 때문.
-top.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@page import="java.util.Date"%> <%@ 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>top.jsp입니다.</title> </head> <body> <h1>top.jsp입니다.</h1> <%=new Date().toLocaleString()%> </body> </html> | cs |
-footer.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <%@ 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> </head> <body> <% //parameter로 전달되는 값 받기 String addr = request.getParameter("addr"); String id = request.getParameter("id"); %> <h3>주소 : <%=addr %> / <%=id %></h3> </body> </html> | cs |
-index.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <%@ 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> </head> <body> <% String addr = "제주도"; //request(parameter로 전달되는)로 넘어오는 한글인코딩처리 request.setCharacterEncoding("UTF-8"); %> <h1>액션태그 - include</h1> <jsp:include page="top.jsp"/> <h3>index.jsp 문서입니다.</h3> <hr color="red" /> <jsp:include page="footer.jsp"> <jsp:param value="<%=addr %>" name="addr"/> <jsp:param value="kim" name="id"/> </jsp:include> </body> </html> | cs |
반응형
'SKILL > JSP' 카테고리의 다른 글
jsp - 강사님노트 (0) | 2018.01.08 |
---|---|
jsp_ 1일차 (0) | 2018.01.08 |