JSP/JSP 공부

[jsp] 5. list 전체출력페이지 만들기

congs 2023. 5. 11. 12:49

1. web에 list.jsp 생성

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품리스트 보기</title>
</head>
<body>
	<h1>상품리스트보기 Product List Page</h1>
	<table border="1">
		<thead>
			<tr>
				<th>번호 pno</th>
				<th>이름 pname</th>
				<th>등록일자 regdate</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list }" var="pvo">
			<tr>
				<td>${pvo.pno }</td>
				<td><a href="detail.pd">${pvo.pname }</a></td>
				<td>${pvo.regdate }</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	
	<!-- 이동 버튼 -->
	<a href="register.pd"><button type="button">상품등록</button></a>
	<a href="index.pd"><button type="button">index</button></a>
</body>
</html>

 

 

 

 


 

2. ProductController에 case "/list.pd" 추가

 

이제 list밑줄을 눌러가면서 register-insert만드는 것처럼 계속 만들기 진행..

https://jungeun980906.tistory.com/318

 

 

 

 

 

	@Override
	public List<productVO> selectList() {
		// 전체출력
		System.out.println(">>> DAO 접속 완료 ");
		query = "select * from product order by pno desc;"; //pno기준 내림차순 = 신상부터
		List<productVO> list = new ArrayList<productVO>();
		
		try {
			pst = conn.prepareStatement(query);
			ResultSet re = pst.executeQuery();
			while(re.next()) {
				list.add(new productVO(re.getInt("pno"),
						re.getString("pname"),
						re.getString("regdate"))); //안에 들어가는 "pno"는 db안의 이름!
			}
			return list;
		} catch (SQLException e) {
			System.out.println("출력 에러");
			e.printStackTrace();
		}
		return null;
	}

 

출력 화면

상품리스트로 이동 클릭
전체 상품의 리스트가 출력