SMALL
안녕하세요, 코린이의 코딩 학습기 채니 입니다.
개인 포스팅용으로 내용에 오류 및 잘못된 정보가 있을 수 있습니다.
@실습문제 - 내정보보기
- session의 속성 loginMember 데이터를 사용할 것
controller
MemberViewServlet
package com.ce.mvc2.member.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class MemberViewServlet
*/
@WebServlet("/member/memberView")
public class MemberViewServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/WEB-INF/views/member/memberView.jsp").forward(request, response);
}
}
memberView.jsp
<%@page import="java.util.Arrays"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/common/header.jsp" %>
<%
// header.jsp에 loginMember를 선언해뒀으므로, 바로 호출 가능!
String memberId = loginMember.getMemberId();
String password = loginMember.getPassword();
String memberName = loginMember.getMemberName();
String birthday = loginMember.getBirthday() != null ? loginMember.getBirthday().toString() : "";
String email = loginMember.getEmail() != null ? loginMember.getEmail() : "";
String phone = loginMember.getPhone();
int point = loginMember.getPoint();
String gender = loginMember.getGender() != null ? loginMember.getGender().name() : "";
String hobby = loginMember.getHobby();
List<String> hobbyList = null;
if(hobby != null) {
String[] hobbyArr = hobby.split(",");
hobbyList = Arrays.asList(hobbyArr); // String[] -> List<String>
}
%>
<section id=enroll-container>
<h2>회원 정보</h2>
<form name="memberUpdateFrm" method="post" action="">
<table>
<tr>
<th>아이디<sup>*</sup></th>
<td>
<input type="text" name="memberId" id="memberId" value="<%= memberId %>" readonly>
</td>
</tr>
<tr>
<th>패스워드<sup>*</sup></th>
<td>
<input type="password" name="password" id="password" value="<%= password %>" required>
</td>
</tr>
<tr>
<th>패스워드확인<sup>*</sup></th>
<td>
<input type="password" id="passwordCheck" value="<%= password %>" required><br>
</td>
</tr>
<tr>
<th>이름<sup>*</sup></th>
<td>
<input type="text" name="memberName" id="memberName" value="<%= memberName %>" required><br>
</td>
</tr>
<tr>
<th>생년월일</th>
<td>
<input type="date" name="birthday" id="birthday" value="<%= birthday %>"><br>
</td>
</tr>
<tr>
<th>이메일</th>
<td>
<input type="email" placeholder="abc@xyz.com" name="email" id="email" value="<%= email %>"><br>
</td>
</tr>
<tr>
<th>휴대폰<sup>*</sup></th>
<td>
<input type="tel" placeholder="(-없이)01012345678" name="phone" id="phone" maxlength="11" value="<%= phone %>" required><br>
</td>
</tr>
<tr>
<th>포인트</th>
<td>
<input type="text" placeholder="" name="point" id="point" value="<%= point %>" readonly><br>
</td>
</tr>
<tr>
<th>성별 </th>
<td>
<input type="radio" name="gender" id="gender0" value="M" <%= "M".equals(gender) ? "checked" : "" %>>
<label for="gender0">남</label>
<input type="radio" name="gender" id="gender1" value="F" <%= "F".equals(gender) ? "checked" : "" %>>
<label for="gender1">여</label>
</td>
</tr>
<tr>
<th>취미 </th>
<td>
<input type="checkbox" name="hobby" id="hobby0" value="운동" <%= hobbyCheck(hobbyList, "운동") %>><label for="hobby0">운동</label>
<input type="checkbox" name="hobby" id="hobby1" value="등산" <%= hobbyCheck(hobbyList, "등산") %>><label for="hobby1">등산</label>
<input type="checkbox" name="hobby" id="hobby2" value="독서" <%= hobbyCheck(hobbyList, "독서") %>><label for="hobby2">독서</label><br />
<input type="checkbox" name="hobby" id="hobby3" value="게임" <%= hobbyCheck(hobbyList, "게임") %>><label for="hobby3">게임</label>
<input type="checkbox" name="hobby" id="hobby4" value="여행" <%= hobbyCheck(hobbyList, "여행") %>><label for="hobby4">여행</label><br />
</td>
</tr>
</table>
<input type="button" onclick="updateMember();" value="정보수정"/>
<input type="button" onclick="deleteMember();" value="탈퇴"/>
</form>
</section>
<%@ include file="/WEB-INF/views/common/footer.jsp" %>
<%!
/**
* compile시 메소드로 선언처리됨.
* 선언위치는 어디든 상관없다.
*/
public String hobbyCheck(List<String> hobbyList, String hobby) {
return hobbyList != null && hobbyList.contains(hobby) ? "checked" : "";
}
%>
LIST
'Java > └ [Servlet & JSP] Practice' 카테고리의 다른 글
[실습문제] 첨부파일 없는 게시글 수정 (0) | 2022.07.05 |
---|---|
[실습문제] 게시글 등록 (0) | 2022.07.02 |
[실습문제] 회원 정보 수정 (0) | 2022.06.26 |