ITPub博客

首页 > 应用开发 > IT综合 > 投票系统原代码(JSP实现) (转)

投票系统原代码(JSP实现) (转)

原创 IT综合 作者:amyz 时间:2007-08-16 20:55:27 0 删除 编辑
投票系统原代码(JSP实现) (转)[@more@]

这是用文本文件作为存储载体的投票系统:

vote.Java:


// Java Document
package vote;
import java.io.*;
import java.util.*;
public class vote extends object
{
 public String filePath="";
 public int n;
 private File voteFile;
 private BufferedReader fileRead;
 private PrintWriter fileWrite;
 public String systemMessage="";
 private String voteStr[]=new String[10];
 public int voteNum[]=new int[10];
 public void createFile()
       throws FileNotFoundException
{
        voteFile=new File(filePath);
            if(!voteFile.exists())
            {
             fileWrite=new PrintWriter(new FileOutputStream(filePath));
             for(int i=0;i             fileWrite.close();
             }
}
public void writeFile()
      throws FileNotFoundException
        {
        fileWrite=new PrintWriter(new FileOutputStream(filePath));
        for(int i=0;i        {
        fileWrite.println(voteNum[i]);
       }
             fileWrite.close();
           }
public void readFile()
          throws FileNotFoundException
                 {
                 fileRead=new BufferedReader(new FileReader(filePath));
                 for(int i=0;i                 {
                 try
                 {voteStr[i]=fileRead.readLine();
                 }
                 catch(IOException f)
                 {
                 voteStr[i]="0";}
                 voteNum[i]=Integer.parseInt(voteStr[i]);
                 }
                 try
                 {      
                 fileRead.close();
                 }
                 catch(IOException d)
                 {
                 systemMessage=d.toString();
                 }
                 }
} 

vote.JSP:

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
SCOpe="request" class="vote.vote"/>
<%
String vote1=request.getParameter("lang");
vote.n=4;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
if(vote1.compareTo("0")==0)
vote.voteNum[0]++;
if(vote1.compareTo("1")==0)
vote.voteNum[1]++;
if(vote1.compareTo("2")==0)
vote.voteNum[2]++;
if(vote1.compareTo("3")==0)
vote.voteNum[3]++;
vote.writeFile();
%>

 see.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>

<%
String vote1=request.getParameter("lang");
vote.n=4;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
int total=0;
float voteFlo[]=new float[5];
for(int i=0;i<4;i++) total+=vote.voteNum[i];
for(int i=0;i<4;i++) voteFlo[i]=150*((float)vote.voteNum[i]/(float)total);
%>



查看调查





 
   
 
 
   
   
 
 
   
   
 
 
   
   
 
 
   
   
 
 
   
 
调查结果
JSP height=8> <%=vote.voteNum[0]%>
ASP height=8> <%=vote.voteNum[1]%>
PHP height=8> <%=vote.voteNum[2]%>
其他 height=8> <%=vote.voteNum[3]%>



index.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>



投票





 
   
 
RM name="form1" method="post" action="vote.jsp">
       
       
         
       
       
         
       
       
         
       
       
         
       
       
         
       
       
         
       
       
你所使用的开发语言

           JSP

           ASP

           PHP

           其他

           
             

     




来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-962694/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3982
  • 访问量
    7896762