eunja511005 / AutoCoding

0 stars 0 forks source link

jsp 구조 페이지 만들 #1

Open eunja511005 opened 1 year ago

eunja511005 commented 1 year ago
eunja511005 commented 1 year ago
  1. /Tutorial/src/main/webapp/WEB-INF/jsp/main/common/main.jsp

    
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>Main</title>
    </head>
    <body>
    <%-- 네비게이션 바를 포함합니다. --%>
    <%@ include file="/WEB-INF/jsp/main/common/nav.jsp" %>
    <hr>
    <%-- 페이지를 동적으로 로딩할 영역을 만듭니다. --%>
    <div id="dynamic-content"></div>
    <hr>
    <%-- 푸터를 포함합니다. --%>
    <%@ include file="/WEB-INF/jsp/main/common/footer.jsp" %>
    
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="/js/main/common/main.js"></script>    

eunja511005 commented 1 year ago
  1. /Tutorial/src/main/resources/static/js/main/common/main.js

    
    $(document).ready(function(){
    loadContent("/content1");
    
    $('a').click(function(event) {
        event.preventDefault();
        var page = $(this).attr('href');
        loadContent(page);
    });
    });

function loadContent(page){ $('#dynamic-content').load(page); }

eunja511005 commented 1 year ago
  1. /Tutorial/src/main/webapp/WEB-INF/jsp/main/common/nav.jsp
    <ul>
    <li><a href="/content1">Content1</a></li>
    <li><a href="/content2">Content2</a></li>
    <li><a href="/content3">Content3</a></li>
    </ul>
eunja511005 commented 1 year ago
  1. /Tutorial/src/main/java/com/eun/tutorial/controller/main/MainController.java
    
    package com.eun.tutorial.controller.main;

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.servlet.ModelAndView;

import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j;

@Slf4j @RequiredArgsConstructor @Controller public class MainController {

@GetMapping("/main")
public ModelAndView main() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("jsp/main/common/main");
    return modelAndView;
}   

@GetMapping("/content1")
public ModelAndView content1() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("jsp/main/content/content1");
    return modelAndView;
}   

@GetMapping("/content2")
public ModelAndView content2() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("jsp/main/content/content2");
    return modelAndView;
}   

@GetMapping("/content3")
public ModelAndView content3() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("jsp/main/content/content3");
    return modelAndView;
}   

}

eunja511005 commented 1 year ago
  1. /Tutorial/src/main/webapp/WEB-INF/jsp/main/content/content1.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Content1</title>
    </head>
    <body>
    <h1>Content1</h1>
    </body>
    </html>
eunja511005 commented 1 year ago

아래 싸이트 접속하여 마음에 드는 템플릿 선택 후 Free Download 후 압축 해제 https://startbootstrap.com/

image

eunja511005 commented 1 year ago

index.html에 있는 내용을 main.jsp와 nave.jsp, footer.jsp, script.jsp 등으로 분리

eunja511005 commented 1 year ago
  1. index.html중 nav.jsp(상단 메뉴)로 가야할 내용 이동
        <nav class="sb-topnav navbar navbar-expand navbar-dark bg-dark">
            <!-- Navbar Brand-->
            <a class="navbar-brand ps-3" href="index.html">Start Bootstrap</a>
            <!-- Sidebar Toggle-->
            <button class="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" id="sidebarToggle" href="#!"><i class="fas fa-bars"></i></button>
            <!-- Navbar Search-->
            <form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
                <div class="input-group">
                    <input class="form-control" type="text" placeholder="Search for..." aria-label="Search for..." aria-describedby="btnNavbarSearch" />
                    <button class="btn btn-primary" id="btnNavbarSearch" type="button"><i class="fas fa-search"></i></button>
                </div>
            </form>
            <!-- Navbar-->
            <ul class="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-user fa-fw"></i></a>
                    <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                        <li><a class="dropdown-item" href="#!">Settings</a></li>
                        <li><a class="dropdown-item" href="#!">Activity Log</a></li>
                        <li><hr class="dropdown-divider" /></li>
                        <li><a class="dropdown-item" href="#!">Logout</a></li>
                    </ul>
                </li>
            </ul>
        </nav>
eunja511005 commented 1 year ago
  1. index.html중 leftNav.jsp(좌측 메뉴)로 가야할 내용 이동
            <div id="layoutSidenav_nav">
                <nav class="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
                    <div class="sb-sidenav-menu">
                        <div class="nav">
                            <div class="sb-sidenav-menu-heading">Core</div>
                            <a class="nav-link" href="index.html">
                                <div class="sb-nav-link-icon"><i class="fas fa-tachometer-alt"></i></div>
                                Dashboard
                            </a>
                            <div class="sb-sidenav-menu-heading">Interface</div>
                            <a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapseLayouts" aria-expanded="false" aria-controls="collapseLayouts">
                                <div class="sb-nav-link-icon"><i class="fas fa-columns"></i></div>
                                Layouts
                                <div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
                            </a>
                            <div class="collapse" id="collapseLayouts" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordion">
                                <nav class="sb-sidenav-menu-nested nav">
                                    <a class="nav-link" href="layout-static.html">Static Navigation</a>
                                    <a class="nav-link" href="layout-sidenav-light.html">Light Sidenav</a>
                                </nav>
                            </div>
                            <a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapsePages" aria-expanded="false" aria-controls="collapsePages">
                                <div class="sb-nav-link-icon"><i class="fas fa-book-open"></i></div>
                                Pages
                                <div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
                            </a>
                            <div class="collapse" id="collapsePages" aria-labelledby="headingTwo" data-bs-parent="#sidenavAccordion">
                                <nav class="sb-sidenav-menu-nested nav accordion" id="sidenavAccordionPages">
                                    <a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseAuth" aria-expanded="false" aria-controls="pagesCollapseAuth">
                                        Authentication
                                        <div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
                                    </a>
                                    <div class="collapse" id="pagesCollapseAuth" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordionPages">
                                        <nav class="sb-sidenav-menu-nested nav">
                                            <a class="nav-link" href="login.html">Login</a>
                                            <a class="nav-link" href="register.html">Register</a>
                                            <a class="nav-link" href="password.html">Forgot Password</a>
                                        </nav>
                                    </div>
                                    <a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseError" aria-expanded="false" aria-controls="pagesCollapseError">
                                        Error
                                        <div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
                                    </a>
                                    <div class="collapse" id="pagesCollapseError" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordionPages">
                                        <nav class="sb-sidenav-menu-nested nav">
                                            <a class="nav-link" href="401.html">401 Page</a>
                                            <a class="nav-link" href="404.html">404 Page</a>
                                            <a class="nav-link" href="500.html">500 Page</a>
                                        </nav>
                                    </div>
                                </nav>
                            </div>
                            <div class="sb-sidenav-menu-heading">Addons</div>
                            <a class="nav-link" href="charts.html">
                                <div class="sb-nav-link-icon"><i class="fas fa-chart-area"></i></div>
                                Charts
                            </a>
                            <a class="nav-link" href="tables.html">
                                <div class="sb-nav-link-icon"><i class="fas fa-table"></i></div>
                                Tables
                            </a>
                        </div>
                    </div>
                    <div class="sb-sidenav-footer">
                        <div class="small">Logged in as:</div>
                        Start Bootstrap
                    </div>
                </nav>
            </div>
eunja511005 commented 1 year ago
  1. index.html중 footer.jsp로 가야할 내용 이동
    <footer class="py-4 bg-light mt-auto">
    <div class="container-fluid px-4">
        <div class="d-flex align-items-center justify-content-between small">
            <div class="text-muted">Copyright &copy; Your Website 2023</div>
            <div>
                <a href="#">Privacy Policy</a> &middot; <a href="#">Terms &amp;
                    Conditions</a>
            </div>
        </div>
    </div>
    </footer>
eunja511005 commented 1 year ago
  1. index.html중 main.jsp로 가야할 내용 이동

    
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title>Auto Coding Main</title>
        <link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.min.css" rel="stylesheet" />
        <link href="css/styles.css" rel="stylesheet" />
        <script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
    </head>
    <body class="sb-nav-fixed">
    <%-- Top Menu --%>
    <%@ include file="/WEB-INF/jsp/main/common/nav.jsp" %>
    
    <div id="layoutSidenav">
        <%-- Left Menu --%>
        <%@ include file="/WEB-INF/jsp/main/common/leftNav.jsp" %>
        <div id="layoutSidenav_content">
            <main>
                <div id="dynamic-content"></div>
            </main>
            <%@ include file="/WEB-INF/jsp/main/common/footer.jsp" %>
        </div>  
    </div>  
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
    <script src="js/scripts.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
    <script src="assets/demo/chart-area-demo.js"></script>
    <script src="assets/demo/chart-bar-demo.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/umd/simple-datatables.min.js" crossorigin="anonymous"></script>
    <script src="js/datatables-simple-demo.js"></script>    
    
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="/js/main/common/main.js"></script>    
    
    </body>

eunja511005 commented 1 year ago
  1. 다운 받은 파일 중 아래 파일들을 프로젝트로 이동 시킨다.
    - css/styles.css" rel="stylesheet
    - js/scripts.js
    - assets/demo/chart-area-demo.js
    - assets/demo/chart-bar-demo.js
    - assets/demo/chart-pie-demo.js
    - js/datatables-simple-demo.js

    image

eunja511005 commented 1 year ago
  1. main.jsp 파일 수정(css, js 파일들의 참조 위치를 복사한 위치에 맞게)

    
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title>Auto Coding Main</title>
        <link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.min.css" rel="stylesheet" />
        <link href="/css/main/common/styles.css" rel="stylesheet" />
        <script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
    </head>
    <body class="sb-nav-fixed">
    <%-- Top Menu --%>
    <%@ include file="/WEB-INF/jsp/main/common/nav.jsp" %>
    
    <div id="layoutSidenav">
        <%-- Left Menu --%>
        <%@ include file="/WEB-INF/jsp/main/common/leftNav.jsp" %>
        <div id="layoutSidenav_content">
            <main>
                <div id="dynamic-content"></div>
            </main>
            <%@ include file="/WEB-INF/jsp/main/common/footer.jsp" %>
        </div>  
    </div>  
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
    <script src="/js/main/common/scripts.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
    <script src="/assets/main/common/chart-area-demo.js"></script>
    <script src="/assets/main/common/chart-bar-demo.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/umd/simple-datatables.min.js" crossorigin="anonymous"></script>
    
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="/js/main/common/main.js"></script>    
    
    </body>

eunja511005 commented 1 year ago
  1. main.jsp 파일 수정에서 스크립트 부분은 script.jsp로 이동
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
    <script src="/js/main/common/scripts.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
    <script src="/assets/main/common/chart-area-demo.js"></script>
    <script src="/assets/main/common/chart-bar-demo.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/umd/simple-datatables.min.js" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>