|
1. 소스
1) formex.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>회원가입 화면</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
body {
min-height: 100vh;
background: -webkit-gradient(linear, left bottom, right top, from(#92b5db), to(#1d466c));
background: -webkit-linear-gradient(bottom left, #92b5db 0%, #1d466c 100%);
background: -moz-linear-gradient(bottom left, #92b5db 0%, #1d466c 100%);
background: -o-linear-gradient(bottom left, #92b5db 0%, #1d466c 100%);
background: linear-gradient(to top right, #92b5db 0%, #1d466c 100%);
}
.input-form {
max-width: 680px;
margin-top: 80px;
padding: 32px;
background: #fff;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 0 8px 20px 0 rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 8px 20px 0 rgba(0, 0, 0, 0.15);
box-shadow: 0 8px 20px 0 rgba(0, 0, 0, 0.15)
}
</style>
</head>
<body>
<div class="container">
<div class="input-form-backgroud row">
<div class="input-form col-md-12 mx-auto">
<h4 class="mb-3">회원가입</h4>
<form class="validation-form" action ="FormEx" method="post" novalidate>
<div class="row">
<div class="col-md-6 mb-3">
<label for="name">이름</label>
<input type="text" class="form-control" name="name" value="" required>
<label for="id">아이디</label>
<input type="text" class="form-control" name="id" value="" required>
<label for="password">비밀번호</label>
<input type="password" class="form-control" name="pw" placeholder="대소문자 포함하여 8자리 입력" value="" required>
</div>
</div>
<div class="mb-3">
<label for="hobby">취미</label><br>
<input type="checkbox" name="hobby" value="read">독서
<input type="checkbox" name="hobby" value="cook">요리
<input type="checkbox" name="hobby" value="run">조깅
<input type="checkbox" name="hobby" value="swim">수영
<input type="checkbox" name="hobby" value="sleep">취침<br/>
<input type="radio" name="major" value="kor">국어
<input type="radio" name="major" value="eng" checked="checked">영어
<input type="radio" name="major" value="mat" >수학
<input type="radio" name="major" value="des" >디자인<br/>
</div>
<div class="mb-3">
<label for="protocol">프로토콜</label><br>
<select name="protocol">
<option value="http">http</option>
<option value="ftp" selected="selected">ftp</option>
<option value="smtp">smtp</option>
<option value="pop">pop</option>
</select><br/>
</div>
<div class="row">
<div class="col-md-8 mb-3">
<label for="root">가입 경로</label>
<select class="custom-select d-block w-100" name="root">
<option value=""></option>
<option>검색</option>
<option>카페</option>
<option>SNS</option>
</select>
</div>
</div>
<hr class="mb-4">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="aggrement" required>
<label class="custom-control-label" for="aggrement">개인정보 수집 및 이용에 동의합니다.</label>
</div>
<div class="mb-4"></div>
<button class="btn btn-dark btn-lg btn-block" type="submit" value="전송">가입 완료</button>
<button class="btn btn-dark btn-lg btn-block" type="reset" value="초기화">초기화</button>
</form>
</div>
</div>
<footer class="my-3 text-center text-small">
<p class="mb-1">© 2021 LEESOYUL</p>
</footer>
</div>
</body>
</html>
2)FormEx.java
package com.vision.servlet04;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
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 FormEx
*/
@WebServlet("/FormEx")
public class FormEx extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FormEx() {
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
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
response.getWriter().append("Served at: ").append(request.getContextPath()).append("<br/>");
String name = request.getParameter("name");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String[] hobbys = request.getParameterValues("hobby");
String major = request.getParameter("major");
String protocol = request.getParameter("protocol");
String root = request.getParameter("root");
PrintWriter out = response.getWriter();
out.println("<html><head></head><body>");
out.println("이름 : " + name + "<br />");
out.println("아이디 : " + id + "<br />");
out.println("비밀번호 : " + pw + "<br />" );
out.println("취미 : " + Arrays.toString(hobbys) + "<br />");
out.println("전공 : " + major + "<br />");
out.println("프로토콜 : " + protocol+ "<br />" );
out.println("가입경로 : " + root);
out.println("</body></html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
2. 폼화면
첫댓글 참잘했어요