| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 954 人关注过本帖
标题:我的JSP--- 投票实例????
只看楼主 加入收藏
tyb
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2004-12-2
收藏
 问题点数:0 回复次数:2 
我的JSP--- 投票实例????

书上有这样一个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",到底是哪里错了呢?

大哥,大姐们,帮帮忙!谢谢了.

搜索更多相关主题的帖子: JSP 实例 投票 
2004-12-02 22:32
dpzxcnq
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2004-10-14
收藏
得分:0 

<input type="submit" name="submit" value="submit" > 应该改为

<input type="submit" name="action" value="submit" >

因为:你第二页的调用:String action=request.getParameter("action");

我也不知道正确不,你试一下吧!

2004-12-07 15:50
tyb
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2004-12-2
收藏
得分:0 

还是不行!

不过谢了!


大家好!!
2004-12-21 12:56
快速回复:我的JSP--- 投票实例????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014895 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved