一个简单问卷调查,为什么在本地测试可以?传上服务器就不行?急啊.....
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.io.*,java.util.*,java.text.*" errorPage=" %>
<html>
<head>
<meta http-equiv="Content-Type">
<title>调查问卷结果</title>
<link href="../css.css" rel=stylesheet>
</head>
<body bgcolor="#ffffff" leftmargin='10px' topmargin='10px'>
<%
if(session.getAttribute("logourl")==null){
session.setAttribute("logourl","123");
String cost=request.getParameter("cost");//获得cost对象
String voteStr[]=new String[3];
int voteNum[]=new int[3];
String path=request.getRealPath("/home/cbinews/webapps/ROOT/vote/");
File f=new File(path,"vote.txt");
if(!f.exists())//检查File.txt是否存在
{
f.createNewFile();//在当前目录下建立一个名为File.txt的文件
File f21=new File(path,"vote.txt");
PrintWriter pw1 = new PrintWriter(new FileOutputStream(f21));
pw1.println("0");
pw1.println("0");
pw1.println("0");
pw1.close();
}
FileReader fr=new FileReader(path + "\\vote.txt");//建立FileReader对象,并实例化为fr
BufferedReader br=new BufferedReader(fr);//建立BufferedReader对象,并实例化为br
//判断读取到的字符串是否不为空
for(int i=0;i<3;i++)
{
try
{
voteStr[i]=br.readLine();
}
catch(IOException fff)
{
voteStr[i]="0";
}
voteNum[i]=Integer.parseInt(voteStr[i]);
}
br.close();//关闭BufferedReader对象
fr.close();//关闭文件
if(cost.equals("1"))
{
voteNum[0]++;
}
if(cost.equals("2"))
{
voteNum[1]++;
}
if(cost.equals("3"))
{
voteNum[2]++;
}
//System.out.println(voteNum[i]);
String path2=request.getRealPath(");
File f2=new File(path2,"vote.txt");
PrintWriter pw = new PrintWriter(new FileOutputStream(f2));
pw.println(voteNum[0]);
pw.println(voteNum[1]);
pw.println(voteNum[2]);
pw.close();
%>
<%
float voteFlo[]=new float[3];
FileReader fr1=new FileReader(path + "\\vote.txt");//建立FileReader对象,并实例化为fr
BufferedReader br1=new BufferedReader(fr1);//建立BufferedReader对象,并实例化为br
//判断读取到的字符串是否不为空
for(int i=0;i<3;i++)
{
try{voteStr[i]=br1.readLine();}
catch(IOException fff){voteStr[i]="0";}
voteNum[i]=Integer.parseInt(voteStr[i]);
}
br1.close();//关闭BufferedReader对象
fr1.close();//关闭文件
float all=(float)voteNum[0]+voteNum[1]+voteNum[2];
for(int j=0;j<3;j++)
{
voteFlo[j]=voteNum[j]/all;
}
%>
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" height="247">
<tr bgcolor="#ffffff"><td height="43"> 市场调查结果</td></tr>
<tr><td><hr size=1></td></tr>
<tr><td> 神舟电脑日前宣布将天运P180C的价格调整为3999元,这已经接近台式机的价格,面对这种情况,你会选择那一个?</td></tr>
<tr><td>
1.台式机<br/> 2.笔记本<br/> 3.不定,看需求<br/></td></tr>
<tr><td><hr size=1></td></tr>
<tr><td>
1. <img src="img/i1.gif" width=<%=(int)100*voteFlo[0]%> height=10> <%=voteNum[0]%><br/>
2. <img src="img/i2.gif" width=<%=(int)100*voteFlo[1]%> height=10> <%=voteNum[1]%><br/>
3. <img src="img/i3.gif" width=<%=(int)100*voteFlo[2]%> height=10> <%=voteNum[2]%><br/>
</td></tr><tr><td height=60 valign='middle'> 总票数:<%=(int)all%><br/></td></tr>
<tr><td><a href="JavaScript:window.close();"> 关闭窗口</a></td></tr>
</table>
<%}else{%>
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" height="247">
<tr><td height=60 valign='middle'> 您已经透过票了!!<br/></td></tr>
<tr><td><a href="JavaScript:window.close();"> 关闭窗口</a></td></tr>
</table><%}%>
</body>
</html>

