package com.sxt.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.sxt.bean.OptionBean;
import com.sxt.bean.OptionBean1;
import com.sxt.bean.Vote_option;
import com.sxt.bean.Vote_option1;
import com.sxt.bean.Vote_subject;
import com.sxt.bean.Vote_subject1;
import com.sxt.bean.Vote_subject2;
import com.sxt.bean.Vote_subjectBean;
import com.sxt.bean.Vote_user;
import com.sxt.bean.Vote_user2;
import com.sxt.dao.BaseDao;
import com.sxt.dao.Vote_userDao;
public class DealServlet extends ConstructorServlet {
/**
* Constructor of the object.
*/
public DealServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void login(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String msg="";
String name=request.getParameter("name");
String pwd=request.getParameter("password");
Vote_userDao vd=new Vote_userDao();
int flag=vd.login(name, pwd);
if(flag==1){
HttpSession session=request.getSession();
session.setAttribute("name", name);
response.sendRedirect("index.jsp");
}else if(flag==-1){
msg="密码错误!";
request.setAttribute("msg", msg);
request.getRequestDispatcher("login.jsp").forward(request, response);
}else{
msg="用户名错误!";
request.setAttribute("msg", msg);
request.getRequestDispatcher("login.jsp").forward(request, response);
}
}
public void register(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name=request.getParameter("userName");
String password1=request.getParameter("password");
String password2=request.getParameter("confirmPassword");
Vote_user vu=new Vote_user(name,password1);
Vote_userDao vd=new Vote_userDao();
if(vd.inster(vu)>=0){
String msg="恭喜:注册成功!请重新登录";
request.setAttribute("msg",msg);
request.getRequestDispatcher("reg_success.jsp").forward(request, response);
}else{
response.sendRedirect("register.jsp");
}
}
public void select1(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int id=0;
int type=0;
String nowtime="";
String endtime="";
String titles=request.getParameter("titles");
Vote_userDao vd=new Vote_userDao();
List<Vote_subject1> list=vd.select1(titles);
for (Vote_subject1 v : list) {
id=v.getVs_id();
type=v.getVs_type();
nowtime=v.getNowtime();
endtime=v.getEndtime();
}
System.out.println(endtime);
List<Vote_subject1> list1=vd.select2(id);
String count=request.getParameter("count");
String pcount=request.getParameter("pcount");
String name=request.getParameter("name");
request.setAttribute("nowtime", nowtime);
request.setAttribute("endtime", endtime);
request.setAttribute("id", id);
request.setAttribute("count", count);
request.setAttribute("pcount", pcount);
request.setAttribute("name", name);
request.setAttribute("type", type);
request.setAttribute("list1", list1);
request.setAttribute("titles", titles);
request.getRequestDispatcher("vote.jsp").forward(request, response);
}
public void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int type=0;
int id=0;
String title=request.getParameter("title");
String tp=request.getParameter("subject.type");
String time=request.getParameter("time");
Date date=new Date();
DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//得到系统的时间
String nowtime=format.format(date);
//结束时间
String endtime="";
if("一小时".equals(time)){
endtime=format.format(date.getTime()+(60*60*1000));
}else if("一天".equals(time)){
endtime=format.format(date.getTime()+(24*60*60*1000));
}else{
endtime=format.format(date.getTime()+(7*24*60*60*1000));
}
if("单选".equals(tp)){
type=1;
}else{
type=2;
}
String[]options=request.getParameterValues("options");
BaseDao bd=new BaseDao();
//根据用户输入信息需要分表添加,先给vote_subject表添加数据
Vote_userDao vd=new Vote_userDao();
int t=vd.inster1(title, type,nowtime,endtime);
//根据用户输入的title查出对应的id,添加到vote_option表
List<Vote_subject2> list=vd.select3(title);
for (Vote_subject2 v : list) {
id=v.getVs_id();
}
int in=vd.update(options, id);
if(t>=0&&in>=0){
String msg="恭喜:操作成功!";
request.setAttribute("msg",msg);
request.getRequestDispatcher("reg_success.jsp").forward(request, response);
}else{
response.sendRedirect("add.jsp");
}
}
public void selectview(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
long total=0;
String vs_id=request.getParameter("id");
Vote_userDao vd=new Vote_userDao();
List<OptionBean1>list=vd.getselect1(vs_id);
for (OptionBean1 o : list) {
total=o.getVcount();
}
List<OptionBean>list1=vd.getview(vs_id);
request.setAttribute("list", list);
request.setAttribute("list1", list1);
request.setAttribute("total", total);
request.getRequestDispatcher("view.jsp").forward(request, response);
}
public void manages(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name=request.getParameter("name");
Vote_userDao vd=new Vote_userDao();
int flag=0;
if(name==""){
response.sendRedirect("login.jsp");
}else{
flag=vd.selectFflag(name);
if(flag==1) {
List<Vote_subject> list=vd.select();
request.setAttribute("list", list);
request.getRequestDispatcher("manage.jsp").forward(request, response);
}else{
request.setAttribute("msg", "您不是管理员没有操作权限");
request.getRequestDispatcher("filter.jsp").forward(request, response);
}
}
}
public void edit(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String title=request.getParameter("title");
String vs_id=request.getParameter("vs_id");
Vote_userDao vd=new Vote_userDao();
List<OptionBean>list1=vd.getview(vs_id);
int type=0;
List<Vote_subject1> list=vd.select1(title);
for (Vote_subject1 v : list) {
type=v.getVs_type();
}
request.setAttribute("vs_id", vs_id);
request.setAttribute("type", type);
request.setAttribute("list1", list1);
request.setAttribute("title", title);
request.getRequestDispatcher("editor.jsp").forward(request, response);
}
public void editortable(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int vs_id=Integer.parseInt(request.getParameter("vs_id"));
String title=request.getParameter("title");
int type=Integer.parseInt(request.getParameter("type"));
String[]options=request.getParameterValues("options");
Vote_userDao vd=new Vote_userDao();
Vote_subjectBean vsb=new Vote_subjectBean(vs_id,title,type);
if(vd.selectvoit_item(vs_id)==true){
request.setAttribute("msg","有用户参与投票不能编辑!" );
request.getRequestDispatcher("filter.jsp").forward(request, response);
}else{
vd.deletevote_option(vs_id);
vd.updatevote_subject(vsb);
vd.update(options, vs_id);
request.setAttribute("msg","编辑成功!" );
request.getRequestDispatcher("reg_success.j
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于jdbc+servlet+filter的网上投票系统源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于jdbc+servlet+filter的网上投票系统源码.zip (92个子文件)
code_20105
.classpath 596B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 617B
.jsdtscope 488B
org.eclipse.wst.jsdt.ui.superType.container 49B
.mymetadata 296B
.gitattributes 378B
src
vote.sql 4KB
db.properties 131B
com
sxt
servlet
ConstructorServlet.java 2KB
DealServlet.java 11KB
dao
Vote_userDao.java 6KB
SerchDao.java 456B
BaseDao.java 3KB
filter
ManagerFilter.java 2KB
LoginFilter.java 2KB
ViewFilter.java 2KB
bean
Vote_subject1.java 608B
Vote_subject.java 588B
OptionBean1.java 603B
Vote_user1.java 172B
Vote_option1.java 172B
OptionBean.java 460B
Vote_option.java 326B
Vote_user2.java 172B
Vote_option3.java 198B
Vote_subjectBean.java 648B
Vote_subject2.java 175B
Vote_user3.java 194B
Vote_user.java 525B
WebRoot
view.jsp 2KB
editor.jsp 4KB
WEB-INF
classes
vote.sql 4KB
db.properties 131B
com
sxt
servlet
ConstructorServlet.class 2KB
DealServlet.class 11KB
dao
Vote_userDao.class 8KB
BaseDao.class 5KB
SerchDao.class 1KB
filter
LoginFilter.class 2KB
ManagerFilter.class 2KB
ViewFilter.class 2KB
bean
Vote_option1.class 496B
Vote_user3.class 549B
Vote_option.class 769B
Vote_subject.class 1KB
Vote_subject1.class 1KB
Vote_subjectBean.class 1KB
Vote_user2.class 490B
Vote_subject2.class 499B
OptionBean.class 971B
Vote_option3.class 495B
OptionBean1.class 1KB
Vote_user.class 915B
Vote_user1.class 480B
lib
commons-logging-1.0.4.jar 37KB
dwr3.jar 1.08MB
mysql-connector-java-5.0.8-bin.jar 528KB
web.xml 3KB
dwr.xml 337B
index.jsp 2KB
reg_success.jsp 1005B
vote.jsp 2KB
filter.jsp 1006B
css
style.css 6KB
add.jsp 4KB
manage.jsp 2KB
register.jsp 3KB
images
join.gif 229B
button_login_over.gif 1KB
bannerCorner.jpg 19KB
button_view.gif 1KB
button_vote.gif 488B
button_login.gif 1KB
button_search.gif 831B
addnew.gif 288B
vote_icon.gif 397B
quote_left.gif 339B
quote_right.gif 326B
title_ico.gif 2KB
arrow_down.gif 149B
new.gif 190B
goback.gif 1KB
button_jion.gif 633B
button_register.gif 3KB
button_submit.gif 2KB
edit.gif 306B
voteBanner.jpg 63KB
META-INF
MANIFEST.MF 36B
login.jsp 2KB
.project 1KB
.gitignore 649B
共 92 条
- 1
资源评论
土豆片片
- 粉丝: 1825
- 资源: 5646
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功