资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Java制作投票系统代码

这篇文章主要为大家详细介绍了Java制作投票系统,文中示例代码介绍的非常详细,零基础也能参考此文章,感兴趣的小伙伴们可以参考一下。

创新互联建站是一家专业提供梁子湖企业网站建设,专注与成都网站设计、成都做网站、H5响应式网站、小程序制作等业务。10年已为梁子湖众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

代码展示:

package com.tarena.wgh.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PollServlet extends HttpServlet {

/**

* The doPost method of the servlet.
* * 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 {    request.setCharacterEncoding("GBK");    //设置请求的编码方式    String item=request.getParameter("item");   //获取投票项    ServletContext servletContext=request.getSession().getServletContext(); //获取ServletContext对象该对象在application范围内有效    Map map=null;    if(servletContext.getAttribute("pollResult")!=null){        map=(Map)servletContext.getAttribute("pollResult"); //获取投票结果        map.put(item,Integer.parseInt(map.get(item).toString())+1); //将当前的投票项加1    }else{      //初始化一个保存投票信息的Map集合,并将选定投票项的投票数设置为1,其他为0        String[] arr={"基础教程类","实例集锦类","经验技巧类","速查手册类","案例剖析类"};        map=new HashMap();        for(int i=0;ialert('投票成功!');window.location.href='showResult.jsp';"); }
}

关于Java制作投票系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果喜欢这篇文章,不如把它分享出去让更多的人看到。


分享文章:Java制作投票系统代码
转载注明:http://cdkjz.cn/article/pighhg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220