书上有这样一个JSP程序:
____________________________________--
文件一:
<!--toupiao1.jsp --> <%@ page contentType="text/html;charset=GBK"%> <%@ page import="java.util.* " %> <%@ page import="java.lang.* " %> <%@ page import="java.io.*" %>
<html>
<head> <title>TOU_PIAO</title> <meta http-equiv="content-Type" content="text/html; charset=gb2312"> </head>
<body bgcolor="#FFFFFF"> <center> <table width="300" border="1" cellspacing="0" cellpadding="0" > <tr> <td>How do you think about JSP?<td> </tr> <form name="toupiao" method="post" action="toupiao2.jsp" > <tr><td><input type="radio" name="toup" value="one" checked>HARD<br> <input type="radio" name="toup" value="two">just so so<br> <input type="radio" name="toup" value="three">Easy<br> <input type="submit" name="submit" value="submit" > </td></tr> </form><tr><td> <% String resultsDir="D:"; FileInputStream tfile=new FileInputStream(resultsDir+ System.getProperty("file.separator")+"EE.txt"); String str=""; int c; while ((c=tfile.read())!=-1) { str=str+(char)c; } if(str!=""){ int first=str.indexOf(":"); int last=str.lastIndexOf(":"); int lenth=str.length();
String First=str.substring(0,first); String Next=str.substring(first+1,last); String Last=str.substring(last+1,lenth);
tfile.close();
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();
long total=b1+b2+b3;
float h0=100*((float)b1/(float)total); float h1=100*((float)b2/(float)total); float h2=100*((float)b3/(float)total);
out.println( b1+"<br>"); out.println( b2+"<br>"); out.println( b3+"<br>"); out.println("Total:"+total); } %> </td> </tr> </table> </center> </body> </html>
__________________________________________________
文件二:
<!--toupiao2.jsp--> <%@ page import="java.util.* " %> <%@ page import="java.lang.* " %> <%@ page import=" java.io.*" %> <% String action=request.getParameter("action"); String toup=request.getParameter("toupiao"); String mydata=""; if(action.compareTo("toupiao")==0) { String resultsDir="D:"; FileWriter resultsFile=new FileWriter(resultsDir+ System.getProperty("file.separator")+"EE.txt",true); File myfile=new File("D:/EE.txt"); if(!(myfile.exists())) { PrintWriter toFile=new PrintWriter(resultsFile); if(toup.compareTo("one")==0) mydata="1:0:0"; if(toup.compareTo("two")==0) mydata="0:1:0"; if(toup.compareTo("three")==0) mydata="0:0:1"; toFile.println(mydata); resultsFile.close(); out.println(mydata); } else { FileInputStream tfile=new FileInputStream(resultsDir+ System.getProperty("file.separator")+"EE.txt");
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); String Next=str.substring(first+1,last); String Last=str.substring(last+1,lenth);
tfile.close();
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();
if(toup.compareTo("one")==0) b1=b1+1; if(toup.compareTo("two")==0) b2=b2+1; if(toup.compareTo("three")==0) b3=b3+1;
Long c1=new Long(b1); Long c2=new Long(b2); Long c3=new Long(b3);
String d1=c1.toString(); String d2=c2.toString(); String d3=c3.toString(); str=d1+":"+d2+":"+d3; RandomAccessFile savefile=new RandomAccessFile(resultsDir+ System.getProperty("file.separator")+"EE.txt","rw"); savefile.writeBytes(str); savefile.close(); out.println(str); } %> <SCRIPT LANGUAGE="JavaScript"> alert("Thank you!"); self.location="toupiao1.jsp"; </SCRIPT> <% } %>
以上两个JSP程序,toupiao1.jsp是没有问题了,为什么"toupiao2.jsp"编译时没错,而运行时就错了呢?
我也在D盘创建了"EE.txt",到底是哪里错了呢?
大哥,大姐们,帮帮忙!谢谢了.