package com.vote.servlet; import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vote.service.VoteService; public class VoteServlet extends HttpServlet { /** * Constructor of the object. */ public VoteServlet() { 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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @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 doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String type = request.getParameter("type"); System.out.println(type); String result = ""; if(!("".equals(type)) && type != null) { result = "{\"success\":true,\"data\":["; if(type.equals("showVote")) { try { result += new VoteService().showUser(); result += "]}"; } catch (SQLException e) { e.printStackTrace(); } } else if (type.equals("vote")) { result = ""; boolean flag = false; String uid = request.getParameter("data"); try { flag = new VoteService().vote(uid); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(flag) result = "{\"success\":true,\"data\":\"投票成功!\"}"; else result = "{\"success\":false,\"data\":\"该ip地址已投过票!\"}"; } } PrintWriter out = response.getWriter(); out.print(result); out.flush(); out.close(); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }
最近下载更多
梦幻瞳 LV1
2022年11月24日
hhhccc LV1
2022年11月6日
wubinbin LV11
2022年10月24日
lhlh123456 LV1
2022年6月17日
744083587 LV1
2022年6月13日
我是阿拉伯王子 LV1
2022年4月20日
起个名字好难起 LV1
2021年12月20日
3089559272 LV11
2021年12月17日
tracy-wang LV1
2021年10月30日
LELLsCORT LV1
2021年9月14日
最近浏览更多
wananall LV13
3月13日
admin_z LV22
1月29日
laishaofe LV7
1月16日
shanmian
1月9日
暂无贡献等级
嗯嗯嗯嗯嗯嗯2528
2023年11月29日
暂无贡献等级
pangzhihui LV12
2023年11月16日
阿凡达 LV9
2023年11月12日
ftc1314 LV12
2023年11月2日
hj1172788262 LV5
2023年10月25日
hhhhyp
2023年10月16日
暂无贡献等级