38-2. Servlet RequestDispatcher

jk·2024년 2월 27일
0

kdt 풀스택

목록 보기
74/127



1. 아래를 구현하시오.

1) 아래의 클래스 구현

 public class MemberListCommand implements MemberCommand {
}
//code
//MemberListCommand.java
public class MemberListCommand implements MemberCommand {
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		MemberDao dao = new MemberDao();
		List<MemberDto> members = dao.memberList();
		request.setAttribute("members", members);
	}
}



2) list.do 명령으로 members 테이블에 있는 모든 멤버를 뿌리시오. 단 아래의 구문을 활용 하시오.

		RequestDispatcher dispatcher = request.getRequestDispatcher("/member_list.jsp");
		dispatcher.forward(request, response);
//code1
//FrontController.java
		} else if(command.equals("/list.do")) {
			System.out.println("모든 멤버 출력");
			System.out.println("--------------");
			mCommand = new MemberListCommand();
			mCommand.execute(request, response);
			viewPage = "member_list.jsp";
		};
<!-- code2 -->
<!-- member_list.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>member_list.jsp</title>
</head>
<body>
<h1>회원 리스트</h1>
<table border="1">
	<tr>
		<td>id</td>
		<td>pw</td>
		<td>email</td>
		<td>address</td>
	</tr>
<c:forEach var="member" items="${members}">
	<tr>
		<td>${member.id}</td>
		<td>${member.pw}</td>
		<td>${member.email}</td>
		<td>${member.address}</td>
	</tr>
</c:forEach>
</table>
</body>
</html>



2. 아래의 객체및 소스 코드를 설명하시오.

		RequestDispatcher dispatcher = request.getRequestDispatcher("/member_list.jsp");
		dispatcher.forward(request, response); 
  • Show "/member_list.jsp" in the in the address like ".do".
  • The "/member_list.jsp" gets the request from this dispatcher.
profile
Brave but clumsy

0개의 댓글