접기
package servlet.member.req.attribute;
import java.io.IOException;
import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
import servlet.member.service.MemberService;
/** * Servlet implementation class SearchMemberByIdServlet */ public class SearchMemberByIdServlet extends HttpServlet { private static final long serialVersionUID = 1L; public SearchMemberByIdServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1. 요청 파라미터 id조회 String id = request.getParameter("id"); //2. MemberService.searchMemberById()호출 해서 회원 정보 조회 //3. 조회한 회원정보(MemberDTO객체)를 request scope에 binding MemberService memberService = new MemberService(); request.setAttribute("member", memberService.searchMemberById(id)); //4. show_member_info.jsp로 수행을 이동 RequestDispatcher rdp = request.getRequestDispatcher("/member/show_member_info.jsp");// /로 시작하면 절대 경로 rdp.forward(request, response); }
}
접기
접기
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd "> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form action="/myweb/search_member" method="post"> <table> <tr> <td>id : </td><td><input type="text" name="id"></td> <td colspan="2"><input type="submit" value="전송"></td> </tr> </table> </form> </body> </html>
접기
접기
<%@page import="servlet.member.dto.MemberDTO"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd "> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% MemberDTO member = (MemberDTO)request.getAttribute("member"); %> id : <%=member.getId() %><br> 이름 : <%=member.getName() %><br> 나이 : <%=member.getAge() %><br> 성별 : <%=member.getSex() %><br> <a href="/myweb/member/search_form.html">이전단계</a> </body> </html>
접기
접기
package servlet.member.service;
import java.util.ArrayList;
import servlet.member.dto.MemberDTO;
public class MemberService { //회원고 관련된 Business Logic을 처리하는 클래스 public MemberDTO searchMemberById(String id){ //인수로 받은 ID로 회원 정보를 찾아 주는 메소드 //회원 조회 로직 MemberDTO mto = new MemberDTO(id,"홍길동",20,"남"); return mto; } public ArrayList<MemberDTO> searchAllMember(){ //전체 회원 정보를 조회하는 메소드 //조회 로직 ArrayList<MemberDTO> list = new ArrayList<MemberDTO>(); list.add(new MemberDTO("1111", "홍길동", 20, "남")); list.add(new MemberDTO("2222", "유재석", 40, "남")); list.add(new MemberDTO("3333", "이영희", 25, "여")); list.add(new MemberDTO("4444", "박철수", 30, "남")); list.add(new MemberDTO("5555", "홍길순", 40, "여")); return list; } }
접기