《WEB应用与开发》在线投票系统课程设计报告.doc_第1页
《WEB应用与开发》在线投票系统课程设计报告.doc_第2页
《WEB应用与开发》在线投票系统课程设计报告.doc_第3页
《WEB应用与开发》在线投票系统课程设计报告.doc_第4页
《WEB应用与开发》在线投票系统课程设计报告.doc_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

hunan city university web应用与开发课程设计报 告设计题目: 在线投票系统 专 业: 信息管理与信息系统 学生姓名: xxxx 班级学号: xxxxx 分组成员: xxxxxxxxxxxxxxxxxxxxxxx 指导教师: xxxxxxxxxxxxxx 2012 年06月08日web应用与开发课程设计报告xx一、设计时间 2012年6月 04日-6月08日总的设计时间为1周, 第17周。具体安排如下:1、分析设计准备阶段(第17周周一至周二) 2、编程调试阶段(第17周周三至第17周周四) 3、书写设计报告和书写说明书阶段(第17周周五) 4、考核阶段(第17周周五) 二、设计地点 信息科学与工程学院机房(新校区510机房)三、设计目的通过对一些实际问题的软件设计,,巩固学习java基础知识方面的基本算法,进一步熟悉基本概念。使学生能将课本的理论知识应用于实践,运用所用学的jsp语言知识编制出较为实用的小系统,培养学生查阅资料的习惯,提高学生独立思考和解决问题的能力。四、设计小组成员 xxxxxxxxxxxxxxxxxxxxxx五、指导老师 xxxxxxxxxxxxxxxxxx六、设计课题 在线投票系统 七、基本思路及关键问题的解决方法1、基本思路 本系统是一个简单的投票系统,主要提供以下功能:系统首页上显示所有投票选项的列表,用户可以通过选中某个选项并点击“投票”按钮进行投票操作。另外,还提供查看投票详细信息的超链接,用户点击后可在另一页面上看到各个投票选项目前的投票情况,主要包括各选项所得的票数、占总票数的百分比等信息,并且以柱形图显示各选项的得票率,可以让用户从直观上看到各项的得票情况2、关键问题如何实现从数据库中的数据调入投票系统的jsp页面中以及把用户在投票系统中的投票结果保存到数据库中。3、解决方法 我们通过加载数据库驱动使access数据库能够与myeclipse中的在线投票系统相连接,从而在dovote.jsp页面中能够从数据库中访问数据库中的数据,也能够在用户投票后对数据库中的数据进行修改。八、算法及流程图算法:首先用户通过在投票首页选择投票功能或者查看结果功能,转入投票页面,然后经过投票处理页面对投票数据进行修改,结果在显示页面显示投票结果。 开 始显示投票表单取得投票的参数是否取得参数 否 结 束显示投票结果将结果写入数据库累加投票数 是 九、调试过程中出现的问题及相应解决办法一、加载数据库驱动时,导入jar包出错解决方法通过把sqljdbc.jar包重新放到项目webrootweb-inflib文件夹下;右键项目名称build pathconfigure build path,重新加载数据库驱动。二、数据库配置时提示异常:“到主机 的 tcp/ip 连接失败。”解决方法可能时因为数据库tcp/ip服务没有开启,重新开启。开启过程:打开 microsoft sql server 2005配置工具目录下的sql server configuration manager,选择mssqlserver协议,然后右边窗口有个tcp/ip协议,双击进入,设置成如下界面,保存,重启sql server服务即可。十、课程设计心得体会课程设计,我明白了要想学习好一门课程,一定要理论与实践相结合,web技术更是如此。要在不同的浏览器上做调试实验,解决兼容性问题。在很多的时候总是感觉捉襟见肘。web技术是计算机方面的重点实践应用课程,所以课程设计在我看来不仅仅是一个知识的巩固,还是一个让我们提高动手能力的途径。通过这次课程设计,我收获的不仅仅是课程上的知识得到实际应用,还有编程的基本操作。使我对所学专业知识得到了充分的应用,锻炼了我发现问题,分析、思考问题、解决问题的能力,使我的实际动手操作能力有所提高,而不仅仅是局限于书本上的知识,对今后的工作学习都大有益处。十一、源程序1)数据表的设计 本系统设计了两张表,表tb-temp保存投票用用户信息,表tb-vote保存投票选项信息。 表tb-temp字段名数据类型字段大小是否为主键idint4是voteipchar20votemselbigint8votetimechar50 表tb-vote字段名数据类型字段大小是否为主键idsmallint2是vote_titlechar50vote_numint4vote_ordersmallint22)值javabean的设计建一个值javabean用来封装存储表tb-temp中的投票选项信息,代码如下:package com.yxq.valuebean;public class votesingle private string id; /存储选项idprivate string title;/存储选项标题private string num;/存储选项所得票数private string order;/存储选项的排列序号public string getid() return id;public void setid(string id) this.id = id;public string getnum() return num;public void setnum(string num) this.num = num;public string getorder() return order;public void setorder(string order) this.order = order;public string gettitle() return title;public void settitle(string title) this.title = title;同样建另一个值javabean用来封装存储表tb-vote中的信息:package com.yxq.valuebean;public class tempsingle private string id;/存储投票用户idprivate string voteip;/ 存储投票用户ipprivate long votemsel;/存储毫秒数private string votetime;/存储yyyy-mm-dd hh:mm:ss形式的时间public long getvotemsel() return votemsel;public void setvotemsel(long votemsel) this.votemsel = votemsel;public string getvotetime() return votetime;public void setvotetime(string votetime) this.votetime = votetime;public string getid() return id;public void setid(string id) this.id = id;public string getvoteip() return voteip;public void setvoteip(string voteip) this.voteip = voteip;3)数据库操作类的编写对于查看投票内容,参与投票和显示结果的操作,都涉及了数据库的操作。这些操作在一个db类中实现,具体代码入下:定义属性及构造方法package com.yxq.toolbean;import java.sql.connection;import java.sql.drivermanager;import java.sql.statement;import java.sql.resultset;import java.util.arraylist;import java.util.list;import com.yxq.valuebean.tempsingle;import com.yxq.valuebean.votesingle;public class db private string classname;/存储数据库驱动类路径private string url;/存储数据库urlprivate string username;/存储登陆数据库的用户名private string password;/存储登陆数据库的密码private connection con;/声明一个connection对象private statement stm;/声明一个statement对象用来执行sql语句private resultset rs;/声明一个resultset对象用来存储结果集public db() /通过构造方法为属性赋值classname = org.apache.derby.jdbc.clientdriver;url = jdbc:derby:/localhost:1527/myeclipse;username = classiccars;password = classiccars;/* * 功能 加载数据库驱动程序 */public void loaddrive() try class.forname(classname); /存储数据库驱动程序 catch (classnotfoundexception e) system.out.println(加载数据库驱动程序失败!);e.printstacktrace(); /向控制器输出提示信息/*获取数据库连接 * 功能 */public void getcon() loaddrive(); /存储数据库驱动程序try con = drivermanager.getconnection(url, username, password);/获取连接 catch (exception e) system.out.println(连接数据库失败!);e.printstacktrace();/* * 功能 获取statement对象 */public void getstm() getcon();/获取数据库连接try stm = con.createstatement();/获取statement类对象 catch (exception e) system.out.println(获取statement对象失败!);e.printstacktrace();/* * 功能 查询数据表,获取结果集 */public void getrs(string sql) getstm();try rs = stm.executequery(sql);/執行sql語句查詢數據表獲取結果集 catch (exception e) system.out.println(查询数据库失败!);e.printstacktrace();/* * 功能 查询数据表,获取投票选项 */public list selectvote(string sql) list votelist = null;if (sql != null & !sql.equals() getrs(sql);/查詢數據表獲取結果集if (rs != null) votelist = new arraylist();try while (rs.next() /依次將結果集中的记录封装到votesingle类对象中votesingle votesingle = new votesingle();votesingle.setid(myttostr(rs.getint(1);votesingle.settitle(rs.getstring(2);votesingle.setnum(myttostr(rs.getint(3);votesingle.setorder(myttostr(rs.getint(4);votelist.add(votesingle);/将votesingle类对象存储到list集合中 catch (exception e) system.out.println(封装tb_vote表中数据失败!);e.printstacktrace(); finally closed(); /关闭 数据库return votelist;/* * 功能 查询数据表,获取指定ip最后一次投票的记录 */public tempsingle selecttemp(string sql) tempsingle tempsingle = null;if (sql != null & !sql.equals() getrs(sql);/查询数据表获取结果集if (rs != null) try while (rs.next() /若该结果集中有记录,说明当前用户投过票tempsingle = new tempsingle();tempsingle.setid(myttostr(rs.getint(1);tempsingle.setvoteip(rs.getstring(2);tempsingle.setvotemsel(rs.getlong(3);tempsingle.setvotetime(rs.getstring(4); catch (exception e) system.out.println(封装tb_temp表中数据失败!);e.printstacktrace(); finally closed(); /关闭数据库return tempsingle;/返回tempsingle类对象中/* * 功能 更新数据表,实现票数累加 */public int update(string sql) int i = -1;if (sql != null & !sql.equals() getstm();/获取statement类对象try i = stm.executeupdate(sql);/执行sql语句更新数据表 catch (exception e) system.out.println(更新数据库失败!);e.printstacktrace(); finally closed();return i;/* * 功能 关闭数据库连接 */public void closed() try if (rs != null)rs.close();/关闭结果集if (stm != null)stm.close();/关闭statement类对象if (con != null)con.close();/关闭数据库连接 catch (exception e) system.out.println(关闭数据库失败!);e.printstacktrace();4)工具类的编写该系统涉及了类型的转换,计算时间差等操作,这些操作在一个类中实现,这样可以实现代码的重复使用。该工具类为mytools,代码如下:package com.yxq.toolbean;import java.text.simpledateformat;import java.util.date;public class mytools /* * 功能 将int型数据转换为string型数据 * 参数 num为要转换的int型数据 * 返回值 string类型 */public static string inttostr(int num)return string.valueof(num);/* * 功能 比较时间。 * 参数 today当前时间,temp为上次投票时间。这两个参数都是以毫秒显示的时间 * 返回值 string类型 */public static string comparetime(long today,long temp)int limittime=60;/设置限制时间为60分钟long count=today-temp;/计算当前时间与上次投票时间相差的毫秒数(该结果一定是大于等于0)if(count=limittime*60*1000)/如果相差小于等于60分钟(1分=60秒,1秒=1000毫秒)return no;else/如果相差大于60分钟return yes;/* * 功能 格式化时间为指定格式。首先通过date类的构造方法根据给出的毫秒数获取一个时间,然后将该时间转换为指定格式,如年-月-日 时:分:秒 * 参数 ms为毫秒数 * 返回值 string类型 */public static string formatdate(long ms)date date=new date(ms);simpledateformat format=new simpledateformat(yyyy-mm-dd hh:mm:ss);string strdate=format.format(date);return strdate;5)显示投票选项的设计当用户访问首页面后,单击“参与投票”就会进入vote.jsp页面显示投票选项,在该页面中先要查询tb_vote数据表获取所有的投票选项,然后逐一显示投票选项的标题 在线投票 没有选项可显示! % int i=0; while(i input type=radio name=ilike value= 注意事项: 1小时内只能投一次票!              6)参与投票的设计% string mess=; /用来保存提示信息 string selectid=request.getparameter(ilike);/获取用户选择 if(selectid=null|selectid.equals()/没有选择投票选项 mess=请选择投票!; else /选择了投票选项 boolean mark=false;/是否允许投票的标志 long today=(new date().gettime();/new date()获取当前时间,通过调用date类的gettime()方法获取从1970年1月1日00:00:00起到当前时间的毫秒数 long last=0;/上次投票的时间(以毫秒显示) string ip=request.getremoteaddr();/获取用户ip地址 string sql=select * from app.tb_temp where votemsel = (select max(votemsel) from tb_temp where voteip=+ip+);/sql语句,功能:从数据表中获取当前用户上次投票时的记录 tempsingle single=mydb.selecttemp(sql); if(single=null)/在tb_temp表中不存在当前ip mark=true; /允许投票 else/存在当前ip,则判断从上次投票到现在是否超过指定时间,本系统指定为60分钟 last=single.getvotemsel();/从该javabean中获取上次投票的时间(以毫秒显示) string result=mytparetime(today,last);/将现在时间与上次投票时的时间进行比较 if(result.equals(yes)/返回yes,表示时间差已超过60分钟,允许投票 mark=true; else/否则,不允许投票 mark=false; string strtime=mytools.formatdate(today);/将当前投票时间(以毫秒显示的)转为年-月-日 时:分:秒的形式 if(mark)/允许投票 /* 【1】记录用户ip和投票时间 */

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论