这是怎么了 好象找不到你的文件\vote.txt !你把文件放在\bin下面试试! 或者你写全部路径 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HTTP Status 404 404错误,应该是找不到这个文件,你看看程序里vote.txt这个路径对不对! <%@ page import="java.util.*,java.lang.*,java.io.*" %><% String action=request.getParameter("action"); String vote=request.getParameter("vote"); String polldata=""; if(action.compareTo("poll")==0){ //生成文件路径和文件名 String resultsDir="/vote"; FileWriter resultsFile=new FileWriter(resultsDir+System.getProperty("file.separator")+"vote.txt",true); //判断文件是否存在 File myfile=new File(resultsDir+System.getProperty("file.separator")+"vote.txt");if(!(myfile.exists())){ PrintWriter toFile=new PrintWriter(resultsFile); if(vote.compareTo("shopping")==0) polldata="1:0:0"; if(vote.compareTo("support")==0) polldata="0:1:0"; if(vote.compareTo("product")==0) polldata="0:0:1"; toFile.println("polldata"); resultsFile.close(); out.println(polldata); }else{ //vate文件存在的情况投票 FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty("file.separator")+"vote.txt"); //创建FileInputStream对象tFile String str=""; int c; while((c=tfile.read())!=-1){ str=str+(char)c; } //找到第一个:的位置 int first=str.indexOf(":"); //找到第二个:的位置 int last=str.lastIndexOf(":"); //取得字符串的长度 int lenth=str.length(); //取出第一个:前的数据 String First=str.substring(0,first); //取出第1个:和第2个:之间的数据 String Next=str.substring(first+1,last); //取出最后1个:后的数据 String Last=str.substring(last+1,lenth); //关闭文件 tfile.close(); //把String转化成long Long a1=new Long(First); Long a2=new Long(Next); Long a3=new Long(Last); long b1=a1.longValue(); long b2=a2.longValue(); long b3=a3.longValue(); //把每次投票结果累加1 if(vote.compareTo("shopping")==0)b1=b1+1; if(vote.compareTo("support")==0)b2=b2+1; if(vote.compareTo("product")==0)b3=b3+1; Long c1=new Long(b1); Long c2=new Long(b2); Long c3=new Long(b3); //把Long转化成String String d1=c1.toString(); String d2=c2.toString(); String d3=c3.toString(); //总数累加 str=d1+":"+d2+":"+d3; //把结果写入vote.txt文件中 RandomAccessFile savefile=new RandomAccessFile(resultsDir+System.getProperty("file.separator")+"vote.txt","rw"); //创建RandomAccessFile对象savefile } %> <script language=javascript> alter("谢谢你的参入"); self.location="../index.jsp"</script><%}%> 不好意思,此代码别的地方也有一些错误,最后应为://把结果写入vote.txt文件中 RandomAccessFile savefile=new RandomAccessFile(resultsDir+System.getProperty("file.separator")+"vote.txt","rw"); //创建RandomAccessFile对象savefilesavefile.writeBytes(str);savefile.close(); } %> <script language=javascript> alert("谢谢你的参入"); self.location="../index.jsp"</script><%}%> 同意 AngusZhang(zhgapp)的观点 js函数嵌套问题 那位高手帮我看看是个什么问题? 这种情况怎么处理啊 请各位帮忙看一段很短的代码 javac后会出现两个附带文件,请问是为什么? JAVA中是否有象C++那种函数的默认参数的用法 如何给jar文件加一个图标呢?谢谢! Java 程序编码规范 每日一问之Java/Weblogic访问数据库篇 java不能运行class文件,求帮助 help---谁能解决这个问题,我给1000分,国庆前结帐,拜托各位帮忙顶一下,谢谢! 大家用Java做什么呢?
404错误,应该是找不到这个文件,你看看程序里vote.txt这个路径对不对!
<%
String action=request.getParameter("action");
String vote=request.getParameter("vote");
String polldata=""; if(action.compareTo("poll")==0){
//生成文件路径和文件名
String resultsDir="/vote";
FileWriter resultsFile=new FileWriter(resultsDir+System.getProperty("file.separator")+"vote.txt",true);
//判断文件是否存在
File myfile=new File(resultsDir+System.getProperty("file.separator")+"vote.txt");
if(!(myfile.exists())){
PrintWriter toFile=new PrintWriter(resultsFile);
if(vote.compareTo("shopping")==0) polldata="1:0:0";
if(vote.compareTo("support")==0) polldata="0:1:0";
if(vote.compareTo("product")==0) polldata="0:0:1";
toFile.println("polldata");
resultsFile.close();
out.println(polldata);
}else{
//vate文件存在的情况投票
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty("file.separator")+"vote.txt");
//创建FileInputStream对象tFile
String str="";
int c;
while((c=tfile.read())!=-1){
str=str+(char)c;
}
//找到第一个:的位置
int first=str.indexOf(":");
//找到第二个:的位置
int last=str.lastIndexOf(":");
//取得字符串的长度
int lenth=str.length();
//取出第一个:前的数据
String First=str.substring(0,first);
//取出第1个:和第2个:之间的数据
String Next=str.substring(first+1,last);
//取出最后1个:后的数据
String Last=str.substring(last+1,lenth);
//关闭文件
tfile.close();
//把String转化成long
Long a1=new Long(First);
Long a2=new Long(Next);
Long a3=new Long(Last);
long b1=a1.longValue();
long b2=a2.longValue();
long b3=a3.longValue();
//把每次投票结果累加1
if(vote.compareTo("shopping")==0)b1=b1+1;
if(vote.compareTo("support")==0)b2=b2+1;
if(vote.compareTo("product")==0)b3=b3+1;
Long c1=new Long(b1);
Long c2=new Long(b2);
Long c3=new Long(b3);
//把Long转化成String
String d1=c1.toString();
String d2=c2.toString();
String d3=c3.toString();
//总数累加
str=d1+":"+d2+":"+d3;
//把结果写入vote.txt文件中
RandomAccessFile savefile=new RandomAccessFile(resultsDir+System.getProperty("file.separator")+"vote.txt","rw");
//创建RandomAccessFile对象savefile
}
%>
<script language=javascript>
alter("谢谢你的参入");
self.location="../index.jsp"
</script>
<%
}
%>
//把结果写入vote.txt文件中
RandomAccessFile savefile=new RandomAccessFile(resultsDir+System.getProperty("file.separator")+"vote.txt","rw");
//创建RandomAccessFile对象savefile
savefile.writeBytes(str);
savefile.close();
}
%>
<script language=javascript>
alert("谢谢你的参入");
self.location="../index.jsp"
</script>
<%
}
%>