티스토리 뷰
<html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>form</title>
- </head>
- <body>
- <form action="formgo" method="POST">
- 이름 <input type="text" name="name" ><br>
- 나이 <input type="text" name="age"><br>
- 취미 <input type="checkbox" name="hobby" value="book"> 책읽기
- <input type="checkbox" name="hobby" value="cook"> 요리
- <input type="checkbox" name="hobby" value="run"> 달리기<br>
- 전공 <input type ="radio" name="major" value="kor"> 국어
- <input type ="radio" name="major" value="eng"> 영어
- <input type ="radio" name="major" value="design"> 디자인<br>
- 이메일 <select name="email">
- <option value="naver"> naver
- <option value="gmail"> gmail
- <option value="daum"> daum
- <option value="nate"> nate
- </select>
- <br>
- <input type="submit" value="제출">
- <input type="reset" value="다시쓰기">
- </form>
- </body>
- </html>
- 서블릿 'formgo'라는 이름을 가진 곳으로 이동
- input type="checkbox" 는 중복선택 가능
<servlet>
- package ex.mystudy.ex;
- 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 formgo
- */
- @WebServlet("/formgo")
- public class formgo extends HttpServlet {
- private static final long serialVersionUID = 1L;
- public formgo() {
- super();
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- response.getWriter().append("Served at: ").append(request.getContextPath());
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- request.setCharacterEncoding("utf-8");
- response.setContentType("text/html; charset=UTF-8");
- out.println("이름 : " + name + "<br>");
- out.println("나이 : " + age + "<br>");
- out.println("전공 : " + major + "<br>");
- out.println("이메일 : " + email + "<br>");
- }
- }
- getParameter는 값 받으려고 ㅇㅇ
- getParameterValues는 값이 여러개일때(배열)
- 문자변환 해줘야 안깨지고 잘 뜸
입력후 '제출'버튼
-> consol창
-> 결과
'JSP' 카테고리의 다른 글
[JSP] Request, Response 간단한 회원가입창 예제 (0) | 2018.07.10 |
---|---|
[JSP] Request, Response 객체 (0) | 2018.07.10 |
[JSP] Servlet - init, destory, @PostConstruct, @PreDestroy (0) | 2018.06.20 |
[JSP] Servlet - doGet, doPost (0) | 2018.06.20 |
[JSP] 개념? (0) | 2018.06.20 |
댓글
최근에 올라온 글
최근에 달린 댓글
링크
- Total
- Today
- Yesterday