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;
hat
  • 781
  • 2
  • 14
  • 25
java java
  • 405
  • 1
  • 11
  • 25
  • 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.. – Vinoth Krishnan Oct 21 '13 at 09: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. – shikjohari Oct 21 '13 at 13:30

2 Answers2

-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..

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
-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();
Debabrata
  • 5
  • 2