본문 바로가기
IT/JSP

[JSP]include로 화면 구현하기

by dya0 2019. 5. 14.

include를 사용해서 구현한 화면

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
32
33
34
35
36
37
38
39
40
41
42
43
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
 
<!DOCTYPE html>
<html>
<head>
    <title>templatetest.jsp</title>
    
    <link rel="stylesheet" href="style.css" 
          type="text/css">
</head>
<%
    String pagefile=request.getParameter("page");
    //처음 보여주는 페이지는 newitem입니다.
    if(pagefile==null){
            pagefile="newItem";
        }
%>
<body>
     <header>
         <h1>상품 목록입니다.</h1><br>
     </header>
     <nav id ="top">
          <jsp:include page = "top.jsp" /><br><br>
     </nav>
     <div id="wrap">
        <aside>
            <!-- 채워주세요 -->
           <jsp:include page = "left.jsp" /> 
 
        </aside>
        <section>
            <!-- 채워주세요 -->
            <jsp:include page = '<%=pagefile+".jsp" %>'/>
        </section>
     </div>
     <footer>
        <!-- 채워주세요 -->
        <jsp:include page = "bottom.jsp" /> 
       <!--  <%@include file = "bottom.jsp" %> -->
     </footer>
</body>
</html>
Colored by Color Scripter

<jsp:include page  = "">과 <%@include file =""%>의 차이

jsp:include 방식은 동적인 페이지 , 페이지가 변할 경우 사용하는 것이 좋다

@include는 페이지가 변하지 않고 정해진 경우 주로 사용한다.

 

파일 구성은 옆 그림과 같이 하면된다.

 

 

 

 

 

 

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
body {
    text-align: center;margin: 0 auto;width: 100%;
}
footer .class{
    text-align:center;
}
header{
    text-align:center;
}
nav > a {
    float: right;
    margin: auto;
    text-decoration: none;
}
nav div{
    background: lightgray;
    text-align:right;
}
nav div > a{
    text-decoration: none;
    color:black;
}
nav div > a:last-child{
    padding-left:10px;
}
aside >  a{
    text-decoration: none; color:black;
}
#wrap > section > ul > li{
    list-style-type:none;
}
aside {
    width: 30%; float: left;
}
 
section {
    float: left;width: 70%
}
footer {
    clear: both;
}
#wrap{
    border:1px solid gray; height:50%;
}
1
2
3
4
5
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<a href="templatetest.jsp?page=newItem">신상품</a>
<a href="templatetest.jsp?page=bestItem">인기상품</a>
<a href="templatetest.jsp?page=usedItem">중고상품</a>

'IT > JSP' 카테고리의 다른 글

[JSP]context  (0) 2019.05.14
[JSP]자바빈 JAVABEAN  (0) 2019.05.14
[JSP]include를 이용한 액션 테스트  (0) 2019.05.14
Forward Action 연습 1  (0) 2019.05.14
액션 태그  (0) 2019.05.14