Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ajaxservlet;doGet方法对单个ajax调用执行多次_Java_Javascript_Ajax_Servlets_Soundmanager2 - Fatal编程技术网

Java ajaxservlet;doGet方法对单个ajax调用执行多次

Java ajaxservlet;doGet方法对单个ajax调用执行多次,java,javascript,ajax,servlets,soundmanager2,Java,Javascript,Ajax,Servlets,Soundmanager2,我使用sound Manager API创建了一个音乐播放器 播放器的形式是标签列表(a),我想为我的歌曲应用投票系统 每次我点击一个链接“a”,就会出现一个div(包含星号)来进行评估并更新数据库 我将其用于ajax和servlet: ajax代码: function voter(){ $('#informations .container .votes_main .votes_gray .votes_buttons a').click(function () {

我使用sound Manager API创建了一个音乐播放器

播放器的形式是标签列表(a),我想为我的歌曲应用投票系统

每次我点击一个链接“a”,就会出现一个div(包含星号)来进行评估并更新数据库

我将其用于ajax和servlet:

ajax代码:

function voter(){

    $('#informations .container .votes_main .votes_gray .votes_buttons a').click(function () {
        valide= true;
        var voteVal = $(this).attr('id');
        $.ajax({
            type:'GET',
            contentType: "charset=utf-8",
            url:''+encodeURI('/RecommandationDefault/rating?vote='+voteVal),
            success:function(response){
                alert(response);
            },
            error: function(e){
                alert('Error: ' + e);
            }
        });
    });
return false;

}
servlet代码:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package votes;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name="rating")
public class rating extends HttpServlet {


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
            } 

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        int i=0;
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write("salut");
        i++;
        System.out.println("executé "+i+" fois");
    } 

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
/*
*要更改此模板,请选择工具|模板
*然后在编辑器中打开模板。
*/
一揽子投票;
导入java.io.IOException;
导入java.io.PrintWriter;
导入java.sql.ResultSet;
导入java.sql.SQLException;
导入javax.servlet.ServletException;
导入javax.servlet.annotation.WebServlet;
导入javax.servlet.http.HttpServlet;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
@WebServlet(name=“评级”)
公共类评级扩展了HttpServlet{
受保护的void processRequest(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
} 
@凌驾
受保护的void doGet(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
int i=0;
response.setContentType(“文本/普通”);
响应。setCharacterEncoding(“UTF-8”);
response.getWriter().write(“salt”);
i++;
System.out.println(“executé”+i+“fois”);
} 
@凌驾
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
}
@凌驾
公共字符串getServletInfo(){
返回“简短描述”;
}// 
}
当我点击一个链接并投票时,当我随后点击另一首歌曲时,只会显示一个警报,我会有“两个警报”,依此类推


问题:我希望每次投票时都出现一个提醒

您也可以发布您的html吗?我猜你的选择器是当你点击链接投票时,选择器有两个项目。一个非常简单的例子是div中的div,两者都具有相同的类$(“.thatClass”).click()会在您单击内部分区时触发两次测试后,问题不在ajax或doGet方法中,问题在SoundManager中。当我单击play时,方法LiReconRant将执行并执行方法vote:function lire_current(){………voter();}和我投票的方法的代码:function voter(){$('#informations.container.voces_main.voces_gray.voces_buttons a')。单击(function(){alert(“voter”)…})); }因此,当我点击一个链接时,当我点击另外两个警报时,只会显示一个警报,然后当我点击另外三个警报时,会显示如此等等。。。