文件名称:
投票系统,基于mvc开发,jsp+servlet+mysql
开发工具:
文件大小: 577kb
下载次数: 0
上传时间: 2010-11-30
详细说明: package com.frog.vote.servlet.front; import java.io.IOException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.frog.vote.bean.UserBean; import com.frog.vote.cons.Const; import com.frog.vote.dao.entity.Vote; import com.frog.vote.factory.ServiceFactory; public class VoteServlet ex tends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("gbk"); resp.setContentType("text/html;charset=gbk"); // 先取出操作参数 String action = req.getParameter("action"); ServletContext application = getServletContext(); // 显示的列表 if ("show".equals(action)) { // 调用service层方法得到所有的 String temp = req.getParameter("page"); int page = 1; if (temp != null) { try { page = Integer.parseInt(temp); } catch (NumberFormatException e) { e.printStackTrace(); } } UserBean ub = (UserBean)req.getSession().getAttribute(Const.USER); int uid = ub.getId(); req.setAttribute("page", ServiceFactory .getVoteService().listUserPage(page,uid)); application.getRequestDispatcher("/WEB-INF/front/list.jsp") .forward(req, resp); return; } else if ("save".equals(action) || "update".equals(action)) { String sid = req.getParameter("id"); String[] answers = req.getParameterValues("choice"); List list = new ArrayList(); int temp; for (String answer : answers) { temp = Integer.parseInt(answer); list.add(temp); } int tid = Integer.parseInt(sid); UserBean ub = (UserBean)req.getSession().getAttribute(Const.USER); Vote vote = new Vote(); vote.setUid(ub.getId()); vote.setTid(tid); vote.setVoteTime(new Timestamp(System.currentTimeMillis())); vote.setAnswer(list); vote.setIp(req.getRemoteAddr()); List listErr = null; if ("update".equals(action)) { // flag = ServiceFactory.getVoteService().update(vote); } else { vote.setStatus(Vote.STATUS_ACTIVE); listErr = ServiceFactory.getVoteService().save(vote); } if (listErr==null) { // resp.sendRedirect(req.getContextPath()+"/main?action=welcome"); application.getRequestDispatcher("/WEB-INF/front/success.jsp").forward(req, resp); return; } req.setAttribute("err", listErr); req.getRequestDispatcher("/err.jsp").forward(req, resp); return; } else if ("delete".equals(action)) { String gid = req.getParameter("gid"); int gidNumber = Integer.parseInt(gid); boolean flag = ServiceFactory.getVoteService().delete(gidNumber); if (flag) { req.getRequestDispatcher("/admin/goods?action=list").forward( req, resp); return; } req.getRequestDispatcher("/err.jsp").forward(req, resp); return; } else if ("modify".equals(action)) { String gid = req.getParameter("gid"); int gidNumber = Integer.parseInt(gid); Vote vote = ServiceFactory.getVoteService().getById(gidNumber); req.setAttribute("detai", vote); if (vote != null) { req.getRequestDispatcher("/admin/goods/modify.jsp").forward( req, resp); return; } req.getRequestDispatcher("/err.jsp").forward(req, resp); return; } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.