当前位置:文档之家› JSP在线投票系统(Java语言)

JSP在线投票系统(Java语言)

JSP程序设计说明书在线投票系统
学院:_________ _ ________ 专业名称:________ _ _________ 班级:_________ _ ________ 学号:___________________ 学生姓名:___________ _______ 指导老师:___________ _ ______ 日期:_________ __ _______
一、基本功能描述
(系统整体介绍、各个子模块介绍)
实现在线投票系统,连接数据库,实现数据库的查询、更新、修改、删除。

获取功能,实现首页与投票页面、投票结果页面之间的相互跳转。

使用JavaBean实现封装。

二、设计思路
主要为系统首页、投票页面和投票结果页面三个页面之间的相互跳转。

三、程序实现
1. 设计过程
(1)Index:系统首页页面的创建
(2)JavaBean:查看投票内容、参与投票和显示投票结果的操作
(3)Access数据库:实现数据库的连接
(4)配置数据源
2. 关键功能的实现及说明
(实现代码+文字说明)
数据库
package com.yxq.toolbean;
import java.sql.*;
import java.io.*;
import java.util.*;
public class DBclass
{
public Connection conn=null;
public Statement stmt=null;
public ResultSet rs=null;
private static String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private static String dbUrl="jdbc:odbc:dbstudent";
//打开数据库连接
public static Connection getConnection()
{
Connection conn=null;
try
{ Class.forName(dbDriver);
conn=DriverManager.getConnection(dbUrl);
}
catch(Exception e)
{ e.printStackTrace(); }
if (conn==null)
{ System.err.println("警告:数据库连接失败!");
}
return conn;
}
//读取结果集
public ResultSet doQuery(String sql)
{
try
{
conn=DBclass.getConnection();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_ READ_ONLY);
rs=stmt.executeQuery(sql);
}
catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
//更新数据
public int doUpdate(String sql)
{
int result=0;
try
{ conn=DBclass.getConnection();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_ READ_ONLY);
result=stmt.executeUpdate(sql);
}
catch(SQLException e)
{ result=0; }
return result;
}
//关闭数据库连接
public void closeConnection()
{ try
{ if (rs!=null) rs.close(); }
catch(Exception e)
{ e.printStackTrace(); }
try
{
if (stmt!=null)
stmt.close();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
if (conn!=null)
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
工具类编写:
package com.yxq.toolbean;
import java.text.SimpleDateFormat;
import java.util.Date;
public class mytools {
public static String intToStr(int num) {
r eturn String.valueOf(num);
public static String compareTime(long today,long temp)
{
i nt limitTime=60;
l ong count=today-temp;
i f(count<=limitTime*60*1000)
return"no";
e lse
return"yes";
}
public static String formatDate(long ms)
{
D ate date=new Date(ms);
S impleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate=format.format(date);
return strDate;
}
}
用JavaBean封装投票选项信息:
package com.yxq.valuebean;
public class VoteSingle {
private String id;
private String title;
private String num;
private String order;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
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;
}
}
同样用另一个JavaBean封装存储表中信息:
package com.yxq.valuebean;
public class TempSingle {
private String id;
private String voteIp;
private long voteMSEL;
private String 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;
}
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;
}
}
3. 运行结果展示及说明
(运行结果截图+文字说明)
首页运行结果:
投票界面:
投票成功:
投票结果页面:
四、结论与心得体会。

相关主题