1. 폼 페이지에서 입력된 데이터를 전달하는 요청 파라미터 값을 JSP 페이지로 가져오는 내장 객체는 무엇인지, 그리고 관련된 메서드에 대해 간단히 설명하시오.
request.getParameter(String para)이다. request 내장 객체의 메서드 종류로는 getParameterValues(String para); getParameterNames(); getParameterMap(); 가 있으며, 요청 파라미터들을 각각 배열, Enumeration 객체 타입, map 객체 타입으로 반환한다.
2. 서버에서 웹 브라우저에 다른 페이지로 강제 이동하도록 명령하는 내장 객체와 관련된 메소드는 무엇인가?
response 내장 객체의 sendRedirect() 메서드이다.
3. 스크립트 태그의 표현문과 같이 데이터를 출력하는 내장 객체는 무엇인가?
웹 브라우저에 데이터를 전송하는 출력 스트림 객체는 out 내장 객체이다. 메소드 종류로는 print(String str); println(String str); newLine(); getBufferSize(); 등이 있다.
4. request 내장 객체를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.
// request.jsp 파일
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Implicit Objects</title>
</head>
<body>
<form action="request_process.jsp" method="get">
<p>아이디 : <input type="text" name="id">
<p>비밀번호 : <input type="text" name="passwd">
<p><input type="submit" value="전송">
</form>
</body>
</html>
// request_process.jsp 파일
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Implicit Objects</title>
</head>
<body>
<% String para = request.getQueryString(); %>
<p>전송된 요청 파라미터 : <strong><%=para%></strong>
</body>
</html>
5. response 내장 객체를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.
// response.jsp 파일
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Implicit Objects</title>
</head>
<body>
<% response.setIntHeader("Refresh", 5); %>
<p>현재 시간은 <%= new java.util.Date(java.util.Calendar.getInstance().getTimeInMillis()) %>
<p><a href="response_data.jsp">Google 홈페이지로 이동하기</a>
</body>
</html>
// response_data.jsp 파일
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Implicit Objects</title>
</head>
<body>
<% response.sendRedirect("http://www.google.com"); %>
</body>
</html>
6. 다음 조건에 맞게 도서 웹 쇼핑몰을 위한 웹 애플리케이션을 만들고 실행 결과를 확인하시오.
(WebContent 폴더 속 파일들)
(src 폴더 dao 패키지의 ProductRepository.java 파일)
package dao;
import java.util.ArrayList;
import dto.Product;
public class ProductRepository {
private ArrayList<Product> listOfProducts = new ArrayList<Product>();
public ArrayList<Product> getAllProducts(){
return listOfProducts;
}
public Product getProductById(String productId) {
Product productById = null;
for(int i=0; i<listOfProducts.size(); i++) {
Product product = listOfProducts.get(i);
if(product != null && product.getProductId() != null
&& product.getProductId().equals(productId)){
productById = product;
break;
}
}
return productById;
}
public ProductRepository() {
Product book_A = new Product("A1", "HTML5+CSS3", 22500);
book_A.setAuthor("황재호");
book_A.setDescription("HTML5, CSS3를 배우는 것보다 더 중요한 것은 그것을 이용해 웹 페이지를 구현하는 것입니다. 이 책은 HTML5 표준과 CSS3 표준을 사용하여 웹 페이지를 구현하는 방법을 중심으로 설명합니다. 웹 페이지 레이아웃, 스마트폰 레이아웃, 태블릿 PC 레이아웃, 소셜커머스 메인 페이지 레이아웃을 담았습니다.");
book_A.setPublisher("한빛 미디어");
book_A.setCategory("웹");
book_A.setUnitsInStock(15);
book_A.setTotalPages(556);
book_A.setReleaseDate("12년도03월");
book_A.setCondition("new");
Product book_B = new Product("B1", "쉽게 배우는 자바 프로그래밍", 27000);
book_B.setAuthor("우종중");
book_B.setDescription("객체 지향의 핵심과 자바의 현대적 기능을 충실히 다루면서도초보자가 쉽게 학습할 수 있게 구성했습니다. 시각화 도구를 활용한 개념 설명과 군더더기 없는 핵심 코드를 통해 개념과 구현을 한 흐름으로 학습할 수 있습니다. 또한 '기초 체력을 다지는 예제 → 셀프 테스트 → 생각을 논리적으로 정리하며 한 단계씩 풀어 가는 도전 과제 → 스토리가 가미된 흥미로운 프로그래밍 문제' 등을 통해 프로그래밍 실력을 차근차근 끌어올릴 수 있습니다.");
book_B.setPublisher("한빛 아카데미");
book_B.setCategory("컴퓨터언어");
book_B.setUnitsInStock(9);
book_B.setTotalPages(692);
book_B.setReleaseDate("17년도07월");
book_B.setCondition("new");
Product book_C = new Product("C1", "정보보안개론", 28000);
book_C.setAuthor("양대일");
book_C.setDescription("이 책은 네트워크의 기본 흐름, 프로그램 실행 구조, 암호의 이해, 보안 솔루션의 구성, 보안 조직과 정책, 보안 전문가가 갖추어야 할 사항 등을 다룹니다. 또한 다른 분야이지만 보안을 공부할 때 알아두면 유용한 내용, 필자가 실무에 종사하면서 체득한 유용한 팁 등도 담고 있습니다. 보안을 처음 공부하거나 전공하는 사람 모두에게 정보 보안 전반에 대한 안목을 길러줄 것입니다.");
book_C.setPublisher("한빛 아카데미");
book_C.setCategory("보안");
book_C.setUnitsInStock(7);
book_C.setTotalPages(584);
book_C.setReleaseDate("18년도10월");
book_C.setCondition("new");
listOfProducts.add(book_A);
listOfProducts.add(book_B);
listOfProducts.add(book_C);
}
}
(src 폴더 dto 패키지의 Product.java 파일)
package dto;
import java.io.Serializable;
public class Product implements Serializable{
private static final long serialVersionUID = -4274700572038677000L;
private String productId;
private String name;
private Integer unitPrice;
private String author;
private String description;
private String publisher;
private String category;
private long unitsInStock;
private long totalPages;
private String releaseDate;
private String condition;
public Product() {
super();
}
public Product(String productId, String name, Integer unitPrice) {
super();
this.productId = productId;
this.name = name;
this.unitPrice = unitPrice;
}
public String getProductId() {
return productId;
}
public String getPname() {
return name;
}
public void setPname(String name) {
this.name = name;
}
public void setProductId(String productId) {
this.productId = productId;
}
public Integer getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Integer unitPrice) {
this.unitPrice = unitPrice;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public long getUnitsInStock() {
return unitsInStock;
}
public void setUnitsInStock(long unitsInStock) {
this.unitsInStock = unitsInStock;
}
public long getTotalPages() {
return totalPages;
}
public void setTotalPages(long totalPages) {
this.totalPages = totalPages;
}
public String getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(String releaseDate) {
this.releaseDate = releaseDate;
}
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
}
'문제풀이 > 쉽게 배우는 JSP 웹프로그래밍' 카테고리의 다른 글
[쉽게 배우는 JSP 웹프로그래밍] 7장 연습문제 (2) | 2020.10.19 |
---|---|
[쉽게 배우는 JSP 웹프로그래밍] 6장 연습문제 (0) | 2020.10.08 |
[쉽게 배우는 JSP 웹프로그래밍] 4장 연습문제 (0) | 2020.09.29 |
[쉽게 배우는 JSP 웹프로그래밍] 3장 연습문제 (0) | 2020.09.28 |
[쉽게 배우는 JSP 웹프로그래밍] 2장 연습문제 (0) | 2020.09.28 |
댓글