0

I have a .jsp file with JavaScript.

If I click to the OK button, I call a JavaScript method. This method detects an id.

I want to send this id to my servlet. In my servlet I want to get the id with getParameter(id).

I have implemented this on my local machine, and it functions well. If I deploy my source code on the sever, the JavaScript method will be called and the id will be detected, but the method doesn't send a request to my servlet.

   <script language="text/javascript">


        function removeLink(){   
            var  id=''; 
            var tmpcounter=0;
            var check=0;
            for (var counter = 0; counter < (document.getElementsByName("inProject[]").length); counter++) {
                if (document.getElementsByName("inProject[]")[counter].checked) {   
                    tmpcounter = tmpcounter+1;
                 }
            }


          for (var zaehler = 0; zaehler < (document.getElementsByName("inProject[]").length); zaehler++) {
            if (document.getElementsByName("inProject[]")[zaehler].checked) {
                check++;
                if((check == tmpcounter) || (tmpcounter==1)){
                    id += 'id='+ document.getElementsByName("inProject[]")[zaehler].value;
                }else{
                    id += 'id='+ document.getElementsByName("inProject[]")[zaehler].value +' OR ';
                }

             }

          }
                    alert(id);
                    location.href='<%=request.getContextPath()%>/issues?action=uploaddeletelink&wherestatement=' + id;   

                    close();


        }

        //-->
    </script>

And this is my OK button:

<td align='right'><a class='funktion' href='javascript:removeLink();'>OK<IMG src="<%=request.getContextPath()%>/issuedb/system/layout/funktionpfeil.gif" width="14" height="9" border="0"></a></td>

On my server, the function will be called, and the id will be detected. The line of code below, which sends the request to my servlet, doesn't function however.

location.href='<%=request.getContextPath()%>/issues?action=uploaddeletelink&wherestatement=' + id;
2
  • 1
    What you are receiving if you alert this value <%=request.getContextPath()%>? If it is working well in local you need to check your path towards servlet.. Commented Oct 21, 2013 at 9:28
  • 1
    Please elaborate the question . You need to check whether something is null. Inspect element in chrome or mozilla and kindly show the exact error. Commented Oct 21, 2013 at 13:30

2 Answers 2

-1

Use AJAX as to call servlet. Get the response back from servlet.

  var xmlHttpReq = false;


if (window.XMLHttpRequest) {
   xmlHttpReq = new XMLHttpRequest();
}

else if (window.ActiveXObject) {
    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpReq.open('POST', strURL, true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 xmlHttpReq.onreadystatechange = function() {
    if (xmlHttpReq.readyState == 4) {
        alert(xmlHttpReq.responseText)
    }
}
xmlHttpReq.send();
Sign up to request clarification or add additional context in comments.

Comments

-1

Use Jquery ajax for this purpose, this is simple and handy. All you need to do is use jquery plugin.

function removeLink(){   
     $.ajax({
     url: "<%=request.getContextPath()%>/issues?action=uploaddeletelink&wherestatement="+id,              
     type: "POST", 
     success: function(data){
      //If you want to return anything in jsp.
       } 
     });
 }

Hope this helps..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.