<header.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="boardList.do">게시판</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</nav>
<templete.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<jsp:include page = "header.jsp"/>
<h2>MVC Framework</h2>
<div class="panel panel-default">
<div class="panel-heading">BOARD</div>
<div class="panel-body">Panel Content</div>
<div class="panel-footer">지능형 IoT_최지연</div>
</div>
</div>
</body>
</html>
<boardList.jsp>
<%@page import="kr.board.domain.Board"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<%
List<Board> list= (List<Board>)request.getAttribute("list");
%>
<div class="container">
<jsp:include page = "header.jsp"/>
<h2>MVC Framework</h2>
<div class="panel panel-default">
<div class="panel-heading">BOARD</div>
<div class="panel-body">
<table class="table table-bordered">
<tr>
<td>번호</td>
<td>제목</td>
<td>작성자</td>
<td>작성일</td>
<td>조회수</td>
</tr>
<%for(Board vo : list){ %>
<tr>
<td><%=vo.getIdx() %></td>
<td><%=vo.getTitle() %></td>
<td><%=vo.getContent() %></td>
<td><%=vo.getWriter() %></td>
<td><%=vo.getCount() %></td>
</tr>
<% } %>
</table>
</div>
<div class="panel-footer">지능형 IoT_최지연</div>
</div>
</div>
</body>
</html>
<BoardListController.java>
package kr.board.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import kr.board.domain.Board;
@WebServlet("/boardList.do")
public class BoardListController extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 게시판 전체 리스트를 가져오기(Model-DAO)
List<Board> list = new ArrayList<Board>();
Board vo1 = new Board(1,"게시판 테스트","게시판 테스트","관리자","2022-05-24", 0);
Board vo2 = new Board(2,"게시판 테스트","게시판 테스트","김운비","2022-05-24", 0);
Board vo3 = new Board(3,"게시판 테스트","게시판 테스트","박매일","2022-05-24", 0);
list.add(vo1);
list.add(vo2);
list.add(vo3);
// 객체바인딩(*****)
request.setAttribute("list", list);
// boardList.jsp
RequestDispatcher rd = request.getRequestDispatcher("board/boardList.jsp");
rd.forward(request, response);
}
}
<Board.java>
package kr.board.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Board {
private int idx;
private String title;
private String content;
private String writer;
private String indate;
private int count;
}
'JSP' 카테고리의 다른 글
JSP Servlet JDBC연결- <MVC Pattern> Model2 실습 (0) | 2022.05.12 |
---|---|
JSP Servlet JDBC연결- <MVC Pattern> Model1 실습 (0) | 2022.05.11 |
JSP Servlet JDBC연결- <MVC Pattern> (0) | 2022.05.11 |
세션(Session) 실습 (0) | 2022.05.09 |
세션(Session) (0) | 2022.05.09 |