1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>FormEx</title> </head> <body> <form action="ExServlet" method="post"> <label>id : <input type="text" name="id_info" size="10em"></label><br> <label>password : <input type="password" name="pw_info" size="10em"></label><br> <label>name : <input type="text" name="name_info"></label><br> <input type="checkbox" name="hobby" value="축구">축구 <input type="checkbox" name="hobby" value="야구" checked="checked">야구 <input type="checkbox" name="hobby" value="농구">농구 <input type="checkbox" name="hobby" value="테니스">테니스<br> <input type="radio" name="sex" value="남">남 <input type="radio" name="sex" value="여">여 <br> <input type="submit" value="전송"> </form> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package com.servletlec.ex; import java.io.IOException; import java.util.ArrayList; 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 ServletParameterEx */ @WebServlet("/ExServlet") public class ServletParameterEx extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public ServletParameterEx() { 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 { // TODO Auto-generated method stub doGet(request, response); request.setCharacterEncoding("EUC-KR"); String id = request.getParameter("id_info"); String pw = request.getParameter("pw_info"); String name = request.getParameter("name_info"); String[] hobby = request.getParameterValues("hobby"); String sex = request.getParameter("sex"); System.out.println("id : " + id); System.out.println("pw : " + pw); System.out.println("name : " + name); System.out.println("sex(남/여) : " + sex); System.out.println("hobby : " + Arrays.toString(hobby)); } } | cs |
결과값 :
한글이 꺠질 경우 처리 방법 : http://chrismare.tistory.com/31?category=1019271
Servlet 데이터 공유 (ServletContext) (0) | 2018.10.17 |
---|---|
Servlet 초기화 Parameter (0) | 2018.10.17 |
한글깨짐현상 처리 (JSP/Servlet) (0) | 2018.10.17 |
서블릿 매핑 방법 (0) | 2018.10.16 |
JSP와 Servlet 특징 및 생명주기 (0) | 2018.10.15 |
댓글 영역