앞에서 배운 것들을 이용하여 회원가입 페이지를 만들어보자.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원가입</title>
<style type="text/css">
label {
width: 160px;
display: inline-block;
float: left;
}
#button {
text-align: center;
}
.container {width: 50%;
}
</style>
<script type="text/javascript">
function check_ok() {
if (document.joinform.name.value == "") {
alert("이름을 써주세요.");
reg_frm.name.focus();
return false;
}
if (document.joinform.regiNum1.value.length != 6) {
alert("주민번호 6글자이어야 합니다.");
reg_frm.jumin_1.focus();
return false;
}
if (document.joinform.regiNum2.value.length != 7) {
alert("주민번호 7글자이어야 합니다.");
reg_frm.jumin_2.focus();
return false;
}
if (document.joinform.id.value.length == 0) {
alert("아이디를 써주세요");
reg_frm.id.focus();
return false;
}
if (document.joinform.id.value.length < 4) {
alert("아이디는 4글자이상이어야 합니다.");
reg_frm.id.focus();
return false;
}
if (document.joinform.password.value == "") {
alert("패스워드는 반드시 입력해야 합니다.");
reg_frm.pwd.focus();
return false;
}
//비밀번호 확인결과가 같은지 체크
if (document.joinform.password.value != document.joinform.chkPassword.value) {
alert("패스워드가 일치하지 않습니다.");
reg_frm.pwd_re.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form method="POST" action="MissionServlet" name="joinform">
<div class="container">
<table>
<tr>
<td>이름<span style="color: red;">*</span></td>
<td><input type="text" id="name" name="name" required></td>
</tr>
<tr>
<td>주민등록번호<span style="color: red;">*</span></td>
<td><input type="text" id="regiNum1" name="regiNum1">-<input type="text" id="regiNum2" name="regiNum2"></td>
</tr>
<tr>
<td>아이디<span style="color: red;">*</span></td>
<td><input type="text" id="id" name="id"></td>
</tr>
<tr>
<td>비밀번호<span style="color: red;">*</span></td>
<td><input type="password" id="password" name="password"></td>
</tr>
<tr>
<td>비밀번호 확인<span style="color: red;">*</span></td>
<td><input type="password" id="chkPassword" name="chkPassword"></td>
</tr>
<tr>
<td>이메일</td>
<td><input type="text" id="firstmail" name="firstmail">@<input type="text" id="lastmail" name="last"> <select id="mail" name="mail" size="1">
<option value="">선택하세요</option>
<option value="gmail">gmail.com</option>
<option value="naver">naver.com</option>
<option value="daum">daum.net</option>
<option value="nate">nate.com</option>
</select></td>
</tr>
<tr>
<td>우편번호</td>
<td><input type="text" id="addrNum" name="addrNum"></td>
</tr>
<tr>
<td>주소</td>
<td><input type="text" id="firstAddr" name="firstAddr"><input type="text" id="lastAddr" name="lastAddr"></td>
</tr>
<tr>
<td>핸드폰번호</td>
<td><input type="text" id="phone" name="phone"></td>
</tr>
<tr>
<td>직업</td>
<td><select id="job" name="job" size="3">
<option value="">선택하세요.</option>
<option value="학생">학생</option>
<option value="컴퓨터/인터넷">컴퓨터/인터넷</option>
<option value="언론">언론</option>
<option value="공무원">공무원</option>
<option value="군인">군인</option>
<option value="서비스업">서비스업</option>
<option value="교육">교육</option>
</select></td>
</tr>
<tr>
<td>메일/SMS 정보 수신</td>
<td><input type="radio" id="chk_mail_yes" name="chk_mail" value="yes" checked="checked">수신 <input type="radio" id="chk_mail_no" name="chk_mail" value="no">거부</td>
</tr>
<tr>
<td>관심분야</td>
<td><input type="checkbox" name="interest" value="생두">생두 <input type="checkbox" name="interest" value="원두">원두 <input type="checkbox" name="interest" value="로스팅">로스팅 <input type="checkbox" name="interest" value="핸드드립">핸드드립 <input type="checkbox" name="interest" value="에스프레소">에스프레소 <input type="checkbox" name="interest" value="창업">창업</td>
</tr>
</table>
<div id="button">
<input type="submit" value="회원가입" onclick="return check_ok();"> <input type="reset" value="취소">
</div>
</div>
</form>
</body>
</html>
package mission;
import java.io.IOException;
import java.io.PrintWriter;
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 MissionServlet
*/
@WebServlet("/MissionServlet")
public class MissionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public MissionServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8"); // post방식에서는 필수적으로 호출
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html><head><meta charset=\"utf-8\" /></head><body>");
String name = request.getParameter("name");
out.println("이름 : " + name);
String regiNum1 = request.getParameter("regiNum1");
String regiNum2 = request.getParameter("regiNum2");
out.println("<br>주민등록번호 : " + regiNum1 + "-" + regiNum2);
String id = request.getParameter("id");
out.println("<br>아이디 : " + id);
String password = request.getParameter("password");
out.println("<br>비밀번호 : " + password);
String firstMail = request.getParameter("firstmail");
if (request.getParameter("mail").trim() == "") {
firstMail += "@" + request.getParameter("lastmail");
} else {
firstMail += "@" + request.getParameter("mail");
}
out.println("<br>이메일 : " + firstMail);
String addrNum = request.getParameter("addrNum");
out.println("<br>우편번호 : " + addrNum);
String address = request.getParameter("firstAddr");
address += request.getParameter("lastAddr");
out.println("<br> 주소 : " + address);
String phone = request.getParameter("phone");
out.println("<br> 핸드폰 번호 : " + phone);
String job = request.getParameter("job");
out.println("<br>직업 : " + job);
String check_mail = request.getParameter("chk_mail");
out.println("<br>메일 수신 여부 : " + check_mail);
out.println("<br>관심분야 : ");
String interests[] = request.getParameterValues("item");
if (interests == null) {
out.print("선택한 항목이 없습니다.");
} else {
for (String interest : interests) {
out.print("[" + interest + "] ");
}
}
out.println("</body></html>");
out.close();
}
}
728x90
반응형
'JSP, Servlet > JSP, Servlet 기초' 카테고리의 다른 글
[JSP/Servlet] 지시자 (page, include, taglib) (0) | 2020.08.10 |
---|---|
[JSP/Servlet] JSP과 Servlet (0) | 2020.08.10 |
[JSP/Servlet] 콤보박스, 리스트박스(<select>) (0) | 2020.08.10 |
[JSP/Servlet] 체크박스(check box) (0) | 2020.08.10 |
[JSP/Servlet] 라디오버튼 실습 (0) | 2020.08.10 |