과정평가_정산기_기록/지역구의원투표 프로그램
(투표하기)과정평가형 정산기 실기 _지역구의원투표 프로그램
값을변경
2022. 2. 19. 17:37
각각의 항목값이 입력되지 않았을 경우 '투표하기' 누르면
'주민번호가 입력되지 않았습니다'와 같이 알림창이 뜨고,
주민번호에 포커스를 이동
select - option : 후보번호는 콤보박스로 구성, [1] 김후보 같은 형태로
<select name="mno">
<option ></option>
<option value="1">[1] 김후보</option>
<option value="2">[2] 이후보</option>
<option value="3">[3] 박후보</option>
<option value="4">[4] 조후보</option>
<option value="5">[5] 최후보</option>
</select>
input - radio : 유권자 확인
<input type="radio" name="jconfirm" value="Y" required>확인
<input type="radio" name="jconfirm" value="N" required>미확인
문제 : radio이 선택되지 않았을때 알림창이 뜨고 (정상), 확인을 누르면 그대로 submit이 된다(비정상).
해결 : required
*required : 양식 제출 전에 radio 체크해야하는지 여부 설정/반환. (출처 : 홈짱.com 여기서 봤어요 )
전체 투표하기
더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="header.jsp"></jsp:include>
<section class="Section">
<h3 class="sectionH3"> 투표하기 </h3>
<form action="vote_regi_Action.jsp" method="post" name="vote_display_form">
<table style="border-collapse: collapse; width: 460px;">
<tr>
<td style="text-align: center;">주민번호</td>
<td><input type="text" name="jno"> 예 : 8906153154726</td>
</tr>
<tr>
<td style="text-align: center;">성명</td>
<td><input type="text" name="jname"></td>
</tr>
<tr>
<td style="text-align: center;">투표번호</td>
<td>
<select name="mno">
<option ></option>
<option value="1">[1] 김후보</option>
<option value="2">[2] 이후보</option>
<option value="3">[3] 박후보</option>
<option value="4">[4] 조후보</option>
<option value="5">[5] 최후보</option>
</select>
</td>
</tr>
<tr>
<td style="text-align: center;">투표시간</td>
<td><input type="text" name="jtime"></td>
</tr>
<tr>
<td style="text-align: center;">투표장소</td>
<td><input type="text" name="jarea"></td>
</tr>
<tr>
<td style="text-align: center;">유권자확인</td>
<td>
<input type="radio" name="jconfirm" value="Y" required>확인
<input type="radio" name="jconfirm" value="N" required>미확인
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" value="투표하기" onclick="return spaceCheck() ">
<input type="reset" value="다시하기">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"></jsp:include>
</body>
</html>
전체 투표하기 액션
더보기
<%@page import="vote.dbcon"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String jno = request.getParameter("jno");
String jname = request.getParameter("jname");
String mno = request.getParameter("mno");
String jtime = request.getParameter("jtime");
String jarea = request.getParameter("jarea");
String jconfirm = request.getParameter("jconfirm");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Connection con = null;
PreparedStatement pstmt = null;
try{
con = dbcon.getConnection();
String sql = "insert into tbl_vote_202005 values(?, ?, ?, ?, ?, ?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, jno);
pstmt.setString(2, jname);
pstmt.setString(3, mno);
pstmt.setString(4, jtime);
pstmt.setString(5, jarea);
pstmt.setString(6, jconfirm);
pstmt.executeUpdate();
response.sendRedirect("vote_display.jsp");
if(pstmt != null) pstmt.close();
if(con != null) con.close();
}catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html>