request 내장 객체
response 내장 객체 / sendRedirect() 메소드
out 내장 객체
request.jsp
<title>Implicit Object</title>
</head>
<body>
<form action="request_process.jsp" method="get">
아이디 : <input type="text" name="id"/><br>
비밀번호 : <input type="text" name="password"/><br>
<input type="submit" value="전송" />
</form>
</body>
request_process.jsp
전송된 요청 파라미터 : <%=request.getQueryString() %>
실행 결과
response.jsp
<title>Implicit Object</title>
</head>
<body>
<%
response.setIntHeader("Refresh", 5);
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
String ap;
if (hour > 12) {
hour -= 12;
ap = "PM";
} else {
ap = "AM";
}
String time = hour+":"+minute+":"+second+" "+ap;
%>
<p>현재 시간: <%=time%></p>
<a href="./response_data.jsp">Google 홈페이지로 이동하기</a>
</body>
response_data.jsp
<%
response.sendRedirect("http://www.google.com");
%>
실행 결과
BookRepository 클래스
BookRepository() 메소드에
book1.setUnitsInStock(1000);
book1.setTotalPages(150);
book1.setReleaseDate("2022.03.01");
등 상세정보 추가하기
public Book getBookId(String bookId) {
Book bookId2 = null;
for (int i = 0; i < listOfBooks.size(); i++) {
Book book = listOfBooks.get(i);
if (book != null && book.getBookId() != null && book.getBookId().equals(bookId)) {
bookId2 = book;
break;
}
}
return bookId2;
}
books.jsp (책은 products로 되어있음)
<div class="row">
<jsp:useBean id="bookDao" class="dao.BookRepository"/>
<%
ArrayList<Book> listOfBooks = bookDao.getAllBooks();
for (Book b:listOfBooks) {
%>
<div class="col-md-10">
<h4><%="["+b.getCategory()+"] " + b.getName()%></h4>
<br>
<p><%=b.getDescription()%>
<p><%=b.getAuthor() + " | " + b.getPublisher() + " | " + b.getUnitPrice() + "원"%>
</div>
<div class="col-md-2">
<p><a href="./book.jsp?id=<%=b.getBookId()%>" class="btn btn-secondary">상세 정보 »</a></p>
</div>
<%
}
%>
</div>
book.jsp (책은 product로 되어있음)
<title>도서정보</title>
</head>
<body>
<%@ include file="menu.jsp" %>
<%!String greeting = "도서 정보";%>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">
<%=greeting%>
</h1>
</div>
</div>
<jsp:useBean id="bookDao" class="dao.BookRepository"/>
<%
String id = request.getParameter("id");
Book book = bookDao.getBookId(id);
%>
<div class="container">
<div class="row">
<div class="col-md-12">
<h3><%="["+book.getCategory()+"] " + book.getName()%></h3>
<p><%=book.getDescription()%>
<p><b>도서코드</b> : <%=book.getBookId()%></p>
<p><b>출판사</b> : <%=book.getPublisher()%></p>
<p><b>저자</b> : <%=book.getAuthor()%></p>
<p><b>재고수</b> : <%=book.getUnitsInStock()%></p>
<p><b>총 페이지수</b> : <%=book.getTotalPages()%></p>
<p><b>출판일</b> : <%=book.getReleaseDate()%></p>
<h3><%=book.getUnitPrice()%>원</h3>
<p><a href="#" class="btn btn-primary">도서 주문</a>
<a href="./books.jsp" class="btn btn-secondary">상품 목록</a>
</p>
</div>
</div>
<hr>
</div>
<%@ include file="footer.jsp" %>
</body>
실행 결과