✅ HTML - modify.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원 정보 수정</title>
<style>
ul {
list-style-type : none;
padding-left : 0;
}
li {
margin : 10px;
}
ul label {
width : 80px;
text-align : left;
float : left;
}
</style>
</head>
<body>
<h1>마이페이지</h1>
<form action="/member/modify.do" method="get">
<fieldset>
<legend>회원 상세 정보</legend>
<ul>
<li>
<label for="member-id">아이디</label>
<input type="text" id="member-id" name="member-id" readonly></input> <!-- 기능을 위한 id, 쿼리스트링 생성을 위한 name -->
</li>
<li>
<label for="member-pw">비밀번호</label>
<input type="password" id="member-pw" name="member-pw"></input>
</li>
<li>
<label for="member-name">이름</label>
<input type="text" id="member-name" name="member-name" readonly></input>
</li>
<li>
<label for="member-age">나이</label>
<input type="text" id="member-age" name="member-age" readonly></input>
</li>
<li>
<label for="member-gender">성별</label>
남<input type="radio" id="member-gender" name="member-gender" value="M"></input>
여<input type="radio" id="member-gender" name="member-gender" value="F"></input>
</li>
<li>
<label for="member-email">이메일</label>
<input type="text" id="member-email" name="member-email"></input>
</li>
<li>
<label for="member-address">주소</label>
<input type="text" id="member-address" name="member-address"></input>
</li>
<li>
<label for="member-phone">전화번호</label>
<input type="text" id="member-phone" name="member-phone"></input>
</li>
<li>
<label for="member-hobby">취미</label>
<input type="text" id="member-hobby" name="member-hobby"></input>
</li>
</ul>
<div>
<input type="submit" value="수정하기">
<input type="reset" value="초기화">
</div>
</fieldset>
</form>
</body>
</html>
✅ Servlet - UpdateServlet
package com.kh.member;
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;
@WebServlet("/member/modify.do")
public class UpdateServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public UpdateServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String memberPw = request.getParameter("member-pw");
String memberGender = request.getParameter("member-gender");
String memberEmail = request.getParameter("member-email");
String memberAddress = request.getParameter("member-address");
String memberPhone = request.getParameter("member-phone");
String memberHobby = request.getParameter("member-hobby");
request.setAttribute("memberPw", memberPw);
request.setAttribute("memberGender", memberGender);
request.setAttribute("memberEmail", memberEmail);
request.setAttribute("memberAddress", memberAddress);
request.setAttribute("memberPhone", memberPhone);
request.setAttribute("memberHobby", memberHobby);
request.getRequestDispatcher("/member/modifyResult.jsp")
.forward(request, response);
}
}
✅ JSP - modifyResult.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원 수정 결과</title>
</head>
<body>
비밀번호 : ${ memberPw }<br>
성별 : ${ memberGender }<br>
이메일 : ${ memberEmail }<br>
주소 : ${ requestScope.memberAddress }<br>
전화번호 : ${ requestScope.memberPhone }<br>
취미 : ${ requestScope.memberHobby }<br>
</body>
</html>
❗ [참고]
- readonly : 텍스트 창에 입력할수 없다.(읽기 전용)