vote.jsp

来自「jsp数据库编程入门」· JSP 代码 · 共 77 行

JSP
77
字号
<html>
<head>
<title>投票统计</title>
</head>
<%@ page contentType="text/html; charset=gb2312"%>
<body>
<center><h2>
投票统计
</h2></center>
<%
   response.setHeader("Cache-Control","no-store");
   response.setDateHeader("Expires",0);
%>
<%!
   //getQuestion(String)函数用来获得文本文件中的问题
   public String[] getQuestion(String s)
   {
     String[] strQ = new String[4];
     String strTemp = null;
     int i;
     java.io.RandomAccessFile rf = null;
     try {
          rf = new java.io.RandomAccessFile(s,"r");
         } catch(Exception e)
         {
           System.out.println(e);
           System.exit(0);
         }
     for(i=0;i<4;i++)
     {
       try {
             strTemp = rf.readLine();
           }catch(Exception e) 
           {
             strTemp = "None Question";
           }
       if(strTemp==null) 
         strTemp = "None Question";
       strQ[i]= strTemp;
     }
     return strQ;
   }
%>
<%
   String s = null;
   String[] question = new String[4];
   s=request.getRealPath("question.txt");
   question = getQuestion(s);
%>
<h3>您最擅长制作什么类型的动态网页?</h3>
<table width="80%" border="0" align="center">
<form name=frm method=post action=writefl.jsp>
<tr>
<td>
<%
   String ss=null;
   for (int i=0;i<4;i++)
   {
     String ques=new String(question[i].getBytes("ISO8859_1"),"GBK");
     ss="<input type=\"radio\" name=\"choice\" value="+i+">"+(char)('A'+i)+". "+ques+"<br><br>";
     out.println(ss);
   }
%>
</td>
</tr>
<tr>
<td align=center><input type="submit" value="我投一票"></td>
</tr>
<tr>
<td align=center><img src="/servlet/VoteImage" width=180 height=120> </td>
</tr>
</form>
</table>
</body>
</html> 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?