본문 바로가기
Spring Framework/jsp 웹

jsp 라디오 버튼 , 체크 박스 , 텍스트 / radio button , checkbox , textarea

by 자유코딩 2017. 11. 22.

jsp 라디오 버튼 , 체크 박스 , 텍스트 / radio button , checkbox , textarea

 

jsp 라디오 버튼 코드

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action = "result.jsp">
        <label for = "hobby">취미 : </label>
        <input type = "radio" name = "hobby" value = "football">축구
        <input type = "radio" name = "hobby" value = "basketball">농구
        <input type = "radio" name = "hobby" value = "baseball">야구
        <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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 
    <form action = "radioResult.jsp">
        <label for = "gender">성별 : </label>
        <input type = "radio" name = "gender" value = "남자" checked = "checked"> 남자    
        <input type = "radio" name = "gender" value = "여자"> 여자<br>
        <label for = "email"><br>메일 수신 여부</label>
        <input type = "radio" name = "email" value = "수신"> 수신
        <input type = "radio" name = "email" value = "거부"> 거부<br>
        <label for = "hobby">
        <br>취미</label><br>
        <input type = "checkbox" name = "hobby" value="영화"> 영화<br>
        <input type = "checkbox" name = "hobby" value="여행"> 여행<br>
        <input type = "checkbox" name = "hobby" value="음악"> 음악<br>
        <input type = "checkbox" name = "hobby" value="독서"> 독서<br>
        <br>
        
        간단한 가입 인사를 입력 하세요 <br>
        <textarea rows="3" cols="35" name = "hello"></textarea>
        
        
        <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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
선택 결과 보여주기 위한 페이지
 
<%
    //request 객체의 getParameter 메소드 이용해서 결과 가져오기
    String gender = request.getParameter("gender");
    String email = request.getParameter("email");
    String hello = request.getParameter("hello");
    String[] hobby = request.getParameterValues("hobby");
    //체크 박스는 여러개이므로 배열로 선언하고 getParameterValues()함수를 사용한다
%>
<br>
성별 : <%=gender %>
<br>
메일 수신 여부 : <%=email %>
<br>
취미 : <%for(int i =0;i<hobby.length;i++){
        out.println(hobby[i]);
    }
%>
<br>
가입인사 : <%=hello %>
 
</body>
</html>
cs

 

댓글