做了一个用户调查小程序,在累积调查结果时用JSP+JAVABEAN来实现:代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<jsp:useBean id="votes" class="votes.vote" scope="request"/>
<body>
<%
String tou=request.getParameter("tou");
votes.checkFile();
votes.setString();
votes.readFile(tou);
votes.getString();
%>
<a href="vote.jsp">感谢您投票,返回</a>
</body>
</html>
却不能实现结果
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<jsp:useBean id="votes" class="votes.vote" scope="request"/>
<body>
<%
String tou=request.getParameter("tou");
votes.checkFile();
votes.setString();
votes.readFile(tou);
votes.getString();
%>
<a href="vote.jsp">感谢您投票,返回</a>
</body>
</html>
却不能实现结果
解决方案 »
- 一个C/S,B/S的简单聊天系统
- frame导航菜单不能完全显示?
- 如何在servlet中获得JSP页面的表单元素input type="file"的路径内容
- 类似163信箱的问题
- 有没有一种jsp标签,能实现业务和数据的分离。
- 百思不得其解啊!!请帮看看关于Bean
- 请指点这段jsp程序,谢谢!急!!!!!!!!
- 除了空指针,为什么我这样还是错(因该是简单的问题),关于“long lUserID=(Long) session.getAttribute("UserID");”
- 请教!!!关于javamail
- 请教:jdbc连接oracle8.0.5的问题!困惑不解
- java新手问题
- javamail接收出错!!
package votes;
import java.io.*;
public class vote
{ public int n=5;
public String ms[]=new String[10];
public int gs[]=new int[10];
public BufferedReader file;
public String filePath="E:\\Tomcat 5.0\\webapps\\jsp-examples\\onlineOvte\\vote.txt";
public PrintWriter pw;
public void setString()throws Exception{
file=new BufferedReader(new InputStreamReader(new FileInputStream(filePath)));
for(int i=0;i<n;i++){
ms[i]=file.readLine();
}
for(int i=0;i<n;i++){
gs[i]=Integer.parseInt(ms[i]);
System.out.println(ms[i]);
}
}
public void checkFile()throws Exception{
File files=new File(filePath);
if(files.exists()==false){
pw=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++){
pw.println(0);
}
pw.close();
}
}
public void readFile(String ch){
String gf=ch;
if(gf!=null&&gf.compareTo("0")==0)gs[0]++;
if(gf!=null&&gf.compareTo("1")==0)gs[1]++;
if(gf!=null&&gf.compareTo("2")==0)gs[2]++;
if(gf!=null&&gf.compareTo("3")==0)gs[3]++;
if(gf!=null&&gf.compareTo("4")==0)gs[4]++;
}
public void getString()throws Exception{
pw=new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++){
pw.println(gs[i]);
System.out.println(gs[i]);
}
pw.close();
}
public static void main(String args[])throws Exception{
vote vot=new vote();
vot.checkFile();
vot.setString();
vot.readFile("0");
vot.getString();
}
}
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<jsp:useBean id="votes" class="votes.vote" scope="request"/>
<body>
<%
String tou=request.getParameter("tou");
votes.checkFile();
votes.setString();
if(tou!=null&&tou.compareTo("0")==0)
votes.gs[0]++;
if(tou!=null&&tou.compareTo("1")==0)
votes.gs[1]++;
if(tou!=null&&tou.compareTo("2")==0)
votes.gs[2]++;
if(tou!=null&&tou.compareTo("3")==0)
votes.gs[3]++;
if(tou!=null&&tou.compareTo("4")==0)
votes.gs[4]++;
votes.getString();
%>
<a href="vote.jsp">感谢您投票,返回</a>
</body>
</html>
这个程序可以实现功能,我不明白的是我把其中的
if(tou!=null&&tou.compareTo("0")==0)
votes.gs[0]++;
if(tou!=null&&tou.compareTo("1")==0)
votes.gs[1]++;
if(tou!=null&&tou.compareTo("2")==0)
votes.gs[2]++;
if(tou!=null&&tou.compareTo("3")==0)
votes.gs[3]++;
if(tou!=null&&tou.compareTo("4")==0)
votes.gs[4]++;
在JAVABEAN中用方法实现然后调用为什么却不行呢??
非常奇怪的问题,我百思不得解,请高手指点
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<h1 align="center">市场调查<br />
</h1>
<form id="form1" name="form1" method="post" action="dovote.jsp">
<div >
<input type="radio" name="tou" value="0" />
每台电脑在15000元以上
<br />
<input type="radio" name="tou" value="1" />
每台电脑在15000-10000元之间<br />
<input type="radio" name="tou" value="2" checked/>
每台在10000-8000元之间<br />
<input type="radio" name="tou" value="3" />
每台在8000-5000之间<br />
<input type="radio" name="tou" value="4" />
每台在5000元以下<br />
<input type="submit" name="Submit" value="提交" />
<input name="vote" type="button" id="vote" value="查看" />
</div>
</form>
</body>
</html>
以上是整个程序的原代码,希望大伙帮我找找原因,保证问题已解决就结贴,可以再加分
public vote(){
}