devote.jsp<%@ page import="java.util.*" contentType = "text/html;charset=GBK" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String cost=request.getParameter("cost");//获得cost对象
vote.n=5;
vote.filePath="vote.txt";
vote.createFile();vote.readFile();if(cost.compareTo("0")==0)
vote.voteNum[0]++;
if(cost.compareTo("1")==0)
vote.voteNum[1]++;
if(cost.compareTo("2")==0)
vote.voteNum[2]++;
if(cost.compareTo("3")==0)
vote.voteNum[3]++;
if(cost.compareTo("4")==0)
vote.voteNum[4]++;vote.writeFile();
%>
<script language="javascript">
alert("感谢你投了宝贵的一票!");
self.location="vote.jsp"
</script>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String cost=request.getParameter("cost");//获得cost对象
vote.n=5;
vote.filePath="vote.txt";
vote.createFile();vote.readFile();if(cost.compareTo("0")==0)
vote.voteNum[0]++;
if(cost.compareTo("1")==0)
vote.voteNum[1]++;
if(cost.compareTo("2")==0)
vote.voteNum[2]++;
if(cost.compareTo("3")==0)
vote.voteNum[3]++;
if(cost.compareTo("4")==0)
vote.voteNum[4]++;vote.writeFile();
%>
<script language="javascript">
alert("感谢你投了宝贵的一票!");
self.location="vote.jsp"
</script>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<jsp:useBean id="vote" scope="request" class="vote.vote"/>
<%
String cost=request.getParameter("cost");
vote.n=5;
vote.filePath="vote.txt";
vote.createFile();
vote.readFile();
int total=0;
float voteFlo[]=new float[5];
for(int i=0;i<5;i++)
total+=vote.voteNum[i];
for(int i=0;i<5;i++)
voteFlo[i]=150*(((float)vote.voteNum[i])/((float)total));
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<style type="text/css">
<!--
@import "css/cssset.css";
-->
<title>调查问卷结果</title>
</head>
<body bgcolor="#ffffff">
<table width="100%" border="0" cellspacing="0"
cellpadding="0" align="center" height="247">
<tr bgcolor="#ffffff">
<td height="43">
<div align="center"><font size="5" color="#330099"><br>
市场调查结果</font></div>
</td>
</tr>
<tr bgcolor="#66ffff" align="center">
<td height="6" width="100%"><font size="3" color="#3333ff">
你人为以你的经济实力,一台电脑的价位在什么地方你可以接受?</font></td>
</tr>
<tr bgcolor="#66ffff">
<td width="100%" height="247">
<table width="90%" border="0" cellspacing="0" cellpadding="4" align="center">
<tr bgcolor="#ffffcc">
<td class="line" colspan="2" height="120">
<p>1.每台在15000元以上<br>
2.每台在15000--10000之间<br>
3.每台在10000--8000之间<br>
4.每台在8000--5000z之间<br>
5.每台在5000元以下</p>
<p>
1.<img scr="bar.jpg" width=<%=voteFlo[0]%> height=8>
<%=vote.voteNum[0]%><br>
2.<img scr="bar.jpg" width=<%=voteFlo[1]%> height=8>
<%=vote.voteNum[1]%><br>
3.<img scr="bar.jpg" width=<%=voteFlo[2]%> height=8>
<%=vote.voteNum[2]%><br>
4.<img scr="bar.jpg" width=<%=voteFlo[3]%> height=8>
<%=vote.voteNum[3]%><br>
5.<img scr="bar.jpg" width=<%=voteFlo[4]%> height=8>
<%=vote.voteNum[4]%><br>
</p>
</td>
</tr>
<tr bgcolor="#ffffcc">
<td class="line" colspan="2" align="center" height="2">
<a href="JavaScript:window.close();">关闭窗口
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
import java.io.*;
import java.util.*;public class vote
{
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]; //创建createfile方法
public void createFile()throws FileNotFoundException{
voteFile=new File(filePath);
if(!voteFile.exists()){
fileWrite=new PrintWriter(new FileOutputStream(filePath));
fileWrite.println("0");
}
} //创建writefile方法
public void writeFile()throws FileNotFoundException{
fileWrite=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++){
fileWrite.println(voteNum[i]);
}
fileWrite.close();
} //创建readflie方法
public void readFile()throws FileNotFoundException{
fileRead=new BufferedReader(new FileReader(filePath));
for(int i=0;i<n;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();
}
}
}