最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

教大家使用java實(shí)現(xiàn)頂一下踩一下功能

 更新時(shí)間:2018年02月10日 13:37:53   作者:上天入地  
這篇文章主要教大家如何使用java實(shí)現(xiàn)頂一下踩一下功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java實(shí)現(xiàn)頂一下踩一下功能的具體代碼,供大家參考,具體內(nèi)容如下

效果圖如下:


主頁(yè)面index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Digg</title> 
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> 
<script type="text/javascript"> 
 
$(function(){ getdigshtml();}) 
 
 
function isdigs(digtype)//頂一下,踩一下操作 
{ 
    $.ajax({   
    type:'POST', 
    url:'Digg', 
    data:'action=digs&digtype='+digtype, 
/*   beforeSend:function(){ 
      $("#vote").hide(); 
      $("#loadings").show(); 
    }, ajax請(qǐng)求顯示loading效果*/ 
    success:function(msg){ 
        switch (msg) 
          { 
/*   后臺(tái)用來(lái)判斷 
              case '1':               
              $("#loadings").hide(); 
              $("#vote").show();  
              alert("請(qǐng)先登錄!"); 
              break; 
            case '2':               
              $("#loadings").hide(); 
              $("#vote").show(); 
              alert("請(qǐng)先下載,再操作!");              
              break; 
            case '4':               
              $("#loadings").hide(); 
              $("#vote").show(); 
              alert("您已經(jīng)參與過(guò)評(píng)價(jià)!");              
              break;*/ 
            case '3': 
              getdigshtml();//重新綁定html 
              //$("#loadings").hide(); 
              //$("#vote").show();   
              alert("謝謝你的參與!"); 
              break; 
           
            default: 
          } 
      } 
    })  
}  
 
function getdigshtml()//獲取頂一下,踩一下html 
{ 
  $.ajax({   
    type:'POST', 
    url:'Digg', 
    data:'action=getdigshtml', 
    success:function(msg){ 
         $("#digg").html(msg); 
      } 
  })  
}  
 
</script> 
<style type="text/css"> 
* { 
  padding:0; 
  margin:0; 
} 
.digg { 
  height: auto; 
  width: 190px; 
  font-size:12px; 
  font-weight:normal; 
} 
.digg a { 
  display: block; 
  height: 48px; 
  width: 189px; 
  background-image: url(images/mark.gif); 
  background-repeat: no-repeat; 
  position: relative; 
  color: #000; 
  text-decoration: none; 
} 
.digg .good { 
  margin-bottom:10px; 
  margin-top:5px; 
} 
 
.digg .good a { 
  background-position: -189px 0px; 
} 
.digg .good a:hover { 
  background-position: 0px 0px; 
} 
.digg .bad a { 
  background-position: -378px 0px; 
} 
.digg .bad a:hover { 
  background-position: -567px 0px; 
} 
.digg a p { 
  padding-left:30px; 
  line-height:25px; 
} 
.digg .bar { 
  background-color: white; 
  height: 5px; 
  left: 20px; 
  overflow: hidden; 
  position: absolute; 
  text-align: left; 
  top: 30px; 
  width: 55px; 
} 
.bar #g_img { 
  background-image: url(images/sprites.gif); 
  background-repeat: repeat-x; 
  height: 5px; 
  width: auto; 
} 
.bar #b_img { 
  background-image: url(images/sprites.gif); 
  background-repeat: repeat-x; 
  height: 5px; 
  width: auto; 
  background-position: 0px -5px; 
} 
.num { 
  color: #333; 
  font: normal normal 100 10px/12px Tahoma; 
  left: 80px; 
  position: absolute; 
  top: 26px; 
} 
.digg .good .bar { 
  border: 1px solid #40A300; 
} 
.digg .bad .bar { 
  border: 1px solid #555; 
} 
 
</style> 
 
<script type="text/javascript"> 
 
</script> 
</head> 
 
<body> 
<div class="digg" id="digg" style="margin-left: auto;margin-right: auto;"> 
 
</div> 
</body> 
</html> 

后臺(tái)servlet:

package com.test; 
 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.text.NumberFormat; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
public class Digg extends HttpServlet { 
  private static Connection con = null; 
  private static Statement stmt = null; 
 
  /** 
   * Constructor of the object. 
   */ 
  public Digg() { 
    super(); 
  } 
 
  /** 
   * Destruction of the servlet. <br> 
   */ 
  public void destroy() { 
    super.destroy(); // Just puts "destroy" string in log 
    // Put your code here 
  } 
 
 
  public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
 
    this.doPost(request, response); 
  } 
 
  public void doPost(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
    request.setCharacterEncoding("utf8"); 
    response.setCharacterEncoding("utf8"); 
    String action = request.getParameter("action"); 
    String digtype = request.getParameter("digtype"); 
    if(action.equals("digs")){ 
      try { 
        response.getWriter().write(dig(digtype)); 
         
      } catch (Exception e) { 
        e.printStackTrace(); 
      } 
    }else if(action.equals("getdigshtml")){ 
      try { 
        response.getWriter().write(getDigHtml()); 
      } catch (Exception e) { 
        e.printStackTrace(); 
      } 
    } 
  } 
  private String dig(String digtype)throws Exception{ 
    String sql =""; 
    if(digtype.equals("digs")){ 
      sql ="update dig set digs=digs+1 where id =1"; 
    }else{ 
      sql ="update dig set undigs=undigs+1 where id =1"; 
    } 
    int num =stmt.executeUpdate(sql); 
    if(num>0){ 
      return "3"; 
    } 
    return "1"; 
  } 
  public static void main(String[] args){  
    NumberFormat nf = NumberFormat.getPercentInstance();  
    nf.setMaximumIntegerDigits(4);  
    nf.setMaximumFractionDigits(6);  
    double d = (double)1/(double)7;  
    System.out.println(nf.format(d));  
    }  
  private String getDigHtml()throws Exception{ 
    NumberFormat nf = NumberFormat.getPercentInstance();  
    nf.setMaximumIntegerDigits(3);  
    nf.setMaximumFractionDigits(2);  
     
    String sql ="select * from dig where id=1"; 
    ResultSet res = stmt.executeQuery(sql); 
    double digSum = 0 ; 
    double unDigSum =0 ; 
    double digSumAll = 0; 
    String digPer = "0%"; 
    String unDigPer = "0%"; 
    while(res.next()){ 
      digSum = res.getInt("digs"); 
      unDigSum = res.getInt("undigs"); 
    } 
    digSumAll = digSum + unDigSum; 
    if(digSumAll !=0 ){ 
      digPer = nf.format(digSum/digSumAll); 
      unDigPer = nf.format(unDigSum/digSumAll); 
    } 
     
    String str="<div class='good'>"; 
      str+="<a href=JavaScript:isdigs('digs') >"; 
      str+="<p>很好</p><div class='bar'><div id='g_img' style='width:"+digPer+"'></div></div>"; 
      str+="<span class='num'>"+digPer+"("+digSum+")</span>"; 
      str+="</a></div><div class='bad'>"; 
      str+="<a href=JavaScript:isdigs('undigs') >"; 
      str+="<p>很差</p><div class='bar'><div id='b_img' style='width:"+unDigPer+"'></div></div>"; 
      str+="<span class='num'>"+unDigPer+"("+unDigSum+")</span>"; 
      str+="</a></div>"; 
   
    return str; 
     
  } 
  /** 
   * Initialization of the servlet. <br> 
   * 
   * @throws ServletException 
   *       if an error occurs 
   */ 
  public void init() throws ServletException { 
    try { 
      Class.forName("com.mysql.jdbc.Driver"); 
      con = DriverManager.getConnection( 
          "jdbc:mysql://172.16.42.39:3306/dig", "root", "12345678"); 
      stmt = con.createStatement(); 
    } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
 
  } 
 
  public void closeCon() { 
    try { 
      stmt.close(); 
      con.close(); 
    } catch (SQLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
 
  } 
} 

sql語(yǔ)句:

CREATE TABLE dig( 
 id INT PRIMARY KEY, 
 digs INT, 
 undigs INT 
); 
INSERT INTO dig VALUES(1,0,0); 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring?Boot實(shí)現(xiàn)web.xml功能示例詳解

    Spring?Boot實(shí)現(xiàn)web.xml功能示例詳解

    這篇文章主要介紹了Spring?Boot實(shí)現(xiàn)web.xml功能,通過(guò)本文介紹我們了解到,在Spring Boot應(yīng)用中,我們可以通過(guò)注解和編程兩種方式實(shí)現(xiàn)web.xml的功能,包括如何創(chuàng)建及注冊(cè)Servlet、Filter以及Listener等,需要的朋友可以參考下
    2023-09-09
  • mybatis的Configuration詳解

    mybatis的Configuration詳解

    這篇文章主要介紹了mybatis的Configuration詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • 詳解用maven搭建springboot環(huán)境的方法

    詳解用maven搭建springboot環(huán)境的方法

    本篇文章主要介紹了詳解用maven搭建springboot環(huán)境的方法,這里整理了詳細(xì)的代碼,非常具有實(shí)用價(jià)值,有需要的小伙伴可以參考下
    2017-08-08
  • maven?插件?assembly?打tar.gz包的詳細(xì)過(guò)程

    maven?插件?assembly?打tar.gz包的詳細(xì)過(guò)程

    這篇文章主要介紹了maven插件assembly打tar.gz包的詳細(xì)過(guò)程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-06-06
  • Mybatis如何實(shí)現(xiàn)@Select等注解動(dòng)態(tài)組合SQL語(yǔ)句

    Mybatis如何實(shí)現(xiàn)@Select等注解動(dòng)態(tài)組合SQL語(yǔ)句

    這篇文章主要介紹了Mybatis如何實(shí)現(xiàn)@Select等注解動(dòng)態(tài)組合SQL語(yǔ)句,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • java并發(fā)學(xué)習(xí)之Executor源碼解析

    java并發(fā)學(xué)習(xí)之Executor源碼解析

    這篇文章主要為大家介紹了java并發(fā)學(xué)習(xí)之Executor源碼示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • java解析XML Node與Element的區(qū)別(推薦)

    java解析XML Node與Element的區(qū)別(推薦)

    下面小編就為大家分享一篇java解析XML Node與Element的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Caffeine本地緩存示例詳解

    Caffeine本地緩存示例詳解

    Caffeine是一種高性能的緩存庫(kù),是基于Java 8的最佳(最優(yōu))緩存框架,這篇文章主要介紹了Caffeine本地緩存相關(guān)知識(shí),需要的朋友可以參考下
    2023-07-07
  • 如何用java對(duì)接微信小程序下單后的發(fā)貨接口

    如何用java對(duì)接微信小程序下單后的發(fā)貨接口

    這篇文章主要介紹了在微信小程序后臺(tái)實(shí)現(xiàn)發(fā)貨通知的步驟,包括獲取Access_token、使用RestTemplate調(diào)用發(fā)貨接口、處理AccessToken緩存以及發(fā)貨成功后的提醒,需要的朋友可以參考下
    2025-03-03
  • Java?Cloneable接口的深拷貝與淺拷貝詳解

    Java?Cloneable接口的深拷貝與淺拷貝詳解

    這篇文章主要為大家詳細(xì)介紹了Java?Cloneable接口的深拷貝與淺拷貝,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03

最新評(píng)論

青州市| 博兴县| 霍邱县| 修文县| 五大连池市| 乌恰县| 遂昌县| 龙州县| 芜湖市| 南宁市| 栖霞市| 抚顺市| 建湖县| 长春市| 常宁市| 辰溪县| 盐池县| 拜泉县| 三门峡市| 韶山市| 仁怀市| 开原市| 枣庄市| 南宁市| 谢通门县| 巍山| 拉萨市| 海兴县| 河曲县| 怀宁县| 阿坝县| 芷江| 甘南县| 洞头县| 辽宁省| 舒兰市| 惠州市| 阿鲁科尔沁旗| 望城县| 资溪县| 基隆市|