欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Java制作投票系統(tǒng)代碼

這篇文章主要為大家詳細(xì)介紹了Java制作投票系統(tǒng),文中示例代碼介紹的非常詳細(xì),零基礎(chǔ)也能參考此文章,感興趣的小伙伴們可以參考一下。

創(chuàng)新互聯(lián)建站是一家專(zhuān)業(yè)提供梁子湖企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為梁子湖眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。

代碼展示:

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. <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 {    request.setCharacterEncoding("GBK");    //設(shè)置請(qǐng)求的編碼方式    String item=request.getParameter("item");   //獲取投票項(xiàng)    ServletContext servletContext=request.getSession().getServletContext(); //獲取ServletContext對(duì)象該對(duì)象在application范圍內(nèi)有效    Map map=null;    if(servletContext.getAttribute("pollResult")!=null){        map=(Map)servletContext.getAttribute("pollResult"); //獲取投票結(jié)果        map.put(item,Integer.parseInt(map.get(item).toString())+1); //將當(dāng)前的投票項(xiàng)加1    }else{      //初始化一個(gè)保存投票信息的Map集合,并將選定投票項(xiàng)的投票數(shù)設(shè)置為1,其他為0        String[] arr={"基礎(chǔ)教程類(lèi)","實(shí)例集錦類(lèi)","經(jīng)驗(yàn)技巧類(lèi)","速查手冊(cè)類(lèi)","案例剖析類(lèi)"};        map=new HashMap();        for(int i=0;i<arr.length;i++){            if(item.equals(arr[i])){    //判斷是否為選定的投票項(xiàng)                map.put(arr[i], 1);            }else{                map.put(arr[i], 0);            }        }    }    servletContext.setAttribute("pollResult", map); //保存投票結(jié)果到ServletContext對(duì)象中    response.setCharacterEncoding("GBK");       //設(shè)置響應(yīng)的編碼方式,如果不設(shè)置彈出的對(duì)話框中的文字將亂碼    PrintWriter out=response.getWriter();    out.println("<script>alert('投票成功!');window.location.href='showResult.jsp';</script>"); }}

關(guān)于Java制作投票系統(tǒng)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果喜歡這篇文章,不如把它分享出去讓更多的人看到。

本文標(biāo)題:Java制作投票系統(tǒng)代碼
文章網(wǎng)址:http://chinadenli.net/article46/pighhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開(kāi)發(fā)動(dòng)態(tài)網(wǎng)站網(wǎng)站內(nèi)鏈網(wǎng)站設(shè)計(jì)Google品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開(kāi)發(fā)