PrintCheckbox.java
package com;
import java.io.IOException;
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;
@WebServlet("/ResultInfo")
public class ResultInfo extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("EUC-KR");
String gender = request.getParameter("gender");
String[] sports = request.getParameterValues("sports");
System.out.println(gender);
System.out.println(Arrays.toString(sports));
}
}
submitCheckbox.html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action="ResultInfo" method="post">
성별<br />
남<input type="radio" value="남" name="gender">
여<input type="radio" value="여" name="gender"><br /><br />
취미<br />
축구<input type="checkbox" value="축구" name="sports">
야구<input type="checkbox" value="야구" name="sports">
농구<input type="checkbox" value="농구" name="sports"><br /><br />
<input type="submit" value="전송">
</form>
</body>
</html>
'Programming > Servlet & JSP' 카테고리의 다른 글
오류페이지 화면 (오류 메세지 가리기) (0) | 2020.02.19 |
---|---|
숫자를 html로 입력받고 구분하여 사진을 servlet에서 보여주기(div, pNum, if, img) (0) | 2020.02.19 |
URL Mapping (url 맵핑) (0) | 2020.02.19 |
servlet에서 ip체크, 구분하여 화면 보여주기 (0) | 2020.02.19 |
html에서 servlet으로 값 전달 (0) | 2020.02.19 |