为什么这段代码不起作用(js 函数)?

Why isn't this code working (js function)?

我正在开发 Java EE 网络应用程序,需要使用 js also.There 是应用程序 jsp 页面上的两个按钮:其中一个是 upVote 和 downVote.I 想让按钮在第一次点击时调用“${upVote}”,并在同一用户第二次点击时调用“${downVote}”。 该流程的逻辑是确保每个用户每次都可以投票一次 question.But 我不知道为什么没有按预期工作。

所以我需要帮助 this.All 回答感谢。

我的代码:

    <c:url var="User" value="/AQ/User">
        <c:param name="answerUserId" value="${question.USERID}" />
    </c:url>
    <c:url var="Question" value="/AQ/UpdateQuestion">
        <c:param name="questionId" value="${question.ID}" />
    </c:url>
    <c:url var="upVote" value="/AQ/UpVoteQuestion">
        <c:param name="questionId" value="${question.ID}" />
        <c:param name="qUserId" value="${question.USERID}"/>
    </c:url>
    <c:url var="downVote" value="/AQ/DownVoteQuestion">
        <c:param name="questionId" value="${question.ID}" />
        <c:param name="qUserId" value="${question.USERID}"/>
    </c:url>

<script type="text/javascript">
    var voteCounter = 0;
    var votedQuestion = 0; 

    function control() {     

        if('${sessionScope[userId]}' <= 0){window.location.href='SignIn'}
        else if(voteCounter >= 1 && votedQuestion == '${question.ID}') {window.location='${downVote}';}
        else{
            voteCounter++;
            votedQuestion = '${question.ID}';
            window.location='${upVote}';
             return false;
        }
    }

    function reverse() {
        if('${sessionScope[userId]}' <= 0){window.location.href='SignIn'}
        else if(voteCounter >= 1 && votedQuestion == '${question.ID}') {window.location='${upVote}';}
        else{
            voteCounter++;
            votedQuestion = '${question.ID}';
            window.location='${downVote}';
             return false;
        }
    }
</script>

还有我的按钮:

<pre style="max-width: 35px; margin-right: 10px;">

                <input class="vote-img" type="image"
                    src="${pageContext.request.contextPath}/resources/images/upVote.png"
                    id="vote" onclick="control()"/>
                <br>
                <label style="float: left; margin-left: 18px;"><c:out value="${question.VOTE }" /></label>
                <input class="vote-img" type="image"
                    src="${pageContext.request.contextPath}/resources/images/downVote.png"
                    id="vote" onclick="reverse()"/>
</pre>

window.location 正在刷新您的浏览器,这意味着再次加载 js 并且每次 voteCounter == 0。