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:include>이용하여 홈페이지 만들기 본문

Template

[기초] <jsp:include>이용하여 홈페이지 만들기

머리방울 2022. 8. 7. 16:31

<jsp:include>를 이용하여 top과 side, bottom의 내용은 고정

메인화면의 내용만 변경되도록 만들어 보자

1. template.jsp

table을 이용하여 2행 3열의 테이블을 생성한다.

위의 그림에서 첫번째 행 top.jsp에는 Login, Join가

두번째 행에는 side.jsp에는 학생등록 학생조회와 main.jsp화면이

3번째 행에는 bottom.jsp Copyright를 넣을 것이다.

 

 <table class="layout">
  <colgroup>
  <col width="20%">
  <col width="80%">
  </colgroup>
   <tr>
  	 <td colspan="2"><jsp:include page="top.jsp"></jsp:include></td>
   </tr>
   <tr>
   	<td><jsp:include page="side.jsp"></jsp:include></td>
   	<td><jsp:include page="${contentPage }"></jsp:include></td

(★main화면이 표시될 곳에는 top과 side의 메뉴를 클릭했을 때 변경되는 화면이 나와야 한다.

이 화면이 나올 데이터를 받을 변수 이름을 contentPage로 지정했다.

contentPage에 어떤 페이지가 나올지는 controller에서 설정한다.)

   </tr>
   <tr>
 	  <td colspan="2"><jsp:include page="bottom.jsp"></jsp:include></td>
   </tr>
 
 </table>

2. index.jsp

index에서 controller 가도록 만들어 준다.

<jsp:forward page="main.do"></jsp:forward>

3. controller

command.equals("/*.do")에서 받은 내용에 따라 우리는

template 화면으로 이동하여 main 화면에서 실행결과를 보여야 한다.

그러므로 실질적으로 어떤 *.do 이던지 최종적으로 이동하는 페이지는
String page = "template.jsp";

이고,  

template main페이지에서 보여줘야하는 내용은 
String contentPage= ""; 변수로 만들고

request.setAttribute("contentPage", contentPage);를 이용하여

template.jsp로 데이터를 보내주어야 한다.

request.setAttribute("contentPage", contentPage); 내용은 공통이기에

한 번만 사용하도록 아래에 빼준다.

boolean isRedirect = false;


1) 메인페이지로 이동(메인)
if(command.equals("/main.do")) {
contentPage = "main.jsp";
}



2) 가입버튼
else if(command.equals("/click_join.do")) {
contentPage="join.jsp";
}

3) 로그인버튼
else if(command.equals("/click_login.do")) {
contentPage="login.jsp";
}

4) 학생등록
else if(command.equals("/reg_stu.do")) {
contentPage = "reg_stu.jsp";
}

5) 학생조회
else if(command.equals("/find_stu.do")) {
contentPage = "find_stu.jsp";
}

각 if, else if문마다 실행되어야 하기 때문에 반복을 피하기 위해 밖으로 뺌
request.setAttribute("contentPage", contentPage);