如何通过JSP代码操纵Ajax javascript代码中的值?

时间:2016-01-12 03:37:22

标签: javascript java ajax jsp servlets

好的,这个javascript代码完美无缺

chat.jsp中,我们得到了这些

function handleReceiveChat() {
            if (receiveReq.readyState == 4) {
                var chat_div = document.getElementById('div_chat');
                var xmldoc = receiveReq.responseXML;
                var message_nodes = xmldoc.getElementsByTagName("message"); 
                var n_messages = message_nodes.length
                for (i = 0; i < n_messages; i++) {
                    var user_node = message_nodes[i].getElementsByTagName("user");
                    var text_node = message_nodes[i].getElementsByTagName("text");
                    var time_node = message_nodes[i].getElementsByTagName("time");
                    chat_div.innerHTML += user_node[0].firstChild.nodeValue + '&nbsp;';
                    chat_div.innerHTML += '<font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font><br />';
                    chat_div.innerHTML += text_node[0].firstChild.nodeValue + '<br />';
                    chat_div.scrollTop = chat_div.scrollHeight;
                    lastMessage = (message_nodes[i].getAttribute('id'));
                }
                mTimer = setTimeout('getChatText();',2000); //Refresh our chat in 2 seconds
            }
        }

问题是我想使用message_nodes[i].getElementsByTagName("text");解码URLEncoder.decode

我想做这样的事情var text_node = "<%=URLEncoder.decode(%> message_nodes[i].getElementsByTagName("text")<%)%>";但是eclipse说得到Syntax error on token ")", delete this token

1 个答案:

答案 0 :(得分:2)

你不能这样做因为JavaScript是客户端,而Jsp是服务器端。