文件名称:投票系统,基于mvc开发,jsp+servlet+mysql
文件大小:577KB
文件格式:RAR
更新时间:2013-12-20 02:53:49
jsp+servlet+mysql
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 extends 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