<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>投票</title>
<!-- javaScript函数 validate()，用来验证是否选择了选项：-->
<script language="JavaScript">
<!--
   function validate(){ 
     var vote0 = document.form.vote[0].checked
         ||document.form.vote[1].checked
         ||document.form.vote[2].checked;
     if(!vote0){
       alert("请您选择！");
       return false;
     }    
   }
-->
</script>
</head>

<body>
<form action="SimpleVoteServlet" method="post" name="form"
	onSubmit="javaScript: return validate();">
<table width="80%" border="0" align="center">
	<tr>
		<td valign="middle">你认为值得花时间去学习JSP技术吗？<br>
		A.<input type="radio" value="A" name="vote">值得<br>
		B.<input type="radio" value="B" name="vote">不值得<br>
		C.<input type="radio" value="C" name="vote">不好说<br>
		<%javax.servlet.http.Cookie cookies[] = request.getCookies();
			boolean voted = false;
			for (int i = 0; i < cookies.length; i++) {
				if ((cookies[i].getName().equals("votedCookie"))
						&& (cookies[i].getValue().equals("true"))) {
					voted = true;
					break;
				}
			}
%> <%if (!voted) {

			%> <input type="submit" value="提交" name="submit"> <%} else {

			%>
		<font color="red">已经投过票了!</font> <%}

			%>
			 <%if (session.getAttribute("voted") == null) {

			%>
		<input type="submit" value="提交" name="submit"> <%} else {

			%> <font
			color="red">已经投过票了!</font> <%}

		%>
			</td>

	</tr>
	<tr>
		<td><a href="simple_showvote.jsp">查看投票结果</a></td>
	</tr>
</table>
</form>
</body>
</html>
