title: call java web service from javascript
body: <p>I would like to call my webservice methods from pure java script code. and that code should work on mozilla browser.</p>
  
  <p>This is my webservice code:</p>
  
  <pre><code>package com.example.core;
  
  import javax.jws.WebMethod;
  import javax.jws.WebParam;
  import javax.jws.WebService;
  import javax.xml.ws.Endpoint;
  
  @WebService
  public class Area {
  
  @WebMethod
  public double square(@WebParam(name="side") double side)
  {
  return side * side;
  }
  
  @WebMethod
  public double rectangle(@WebParam(name="length") double length,@WebParam(name="breadth") double breadth)
  {
   return length * breadth;
   }
  
   public static void main(String[] args) {
   Area area = new Area();
  String url = "http://localhost:8090/area"; // end point of webservice.
   System.out.println(url+"?wsdl");
   Endpoint.publish(url, area);  // publishing the webservice
  }
  }
  </code></pre>
  
  <p>Here is my HTML file: </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta content="utf-8" http-equiv="encoding"&gt;
  &lt;meta content="text/xml;charset=utf-8" http-equiv="Content-Type"&gt;
  &lt;script language="javascript"&gt;
  
  function call()
  {
  var side = sideid.value;
  var side1 = sideid1.value;
  var req = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"+"&lt;soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://core.codon.com/\"&gt;&lt;soapenv:Body&gt;&lt;web:rectangle&gt;&lt;length&gt;" + side+ "&lt;/length&gt;&lt;breadth&gt;" + side1+ "&lt;/breadth&gt;&lt;/web:rectangle&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;";
   //var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
   //var reqXML = xmlDoc.loadXML(req);
   var xmlDoc=document.implementation.createDocument("", "", null);
   xmlDoc.async=false;
   xmlDoc.onload = req; 
   //var reqXML = xmlDoc.load(req);
  var xmlhttp;
  if(window.XMLHttpRequest){
    xmlhttp=new XMLHttpRequest();
   }
   xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4)
   {
    var response = xmlhttp.responseXML;
  
    alert(response.selectSingleNode(".//return").text);
     alert("======"+response);
    }
  }
   var soapaction = "http://core.example.com/rectangle";
   xmlhttp.open("POST","http://localhost:8090/area?wsdl",true);
   xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
   xmlhttp.setRequestHeader("SOAPAction", soapaction);
   xmlhttp.send(req);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
   Side Length: &lt;input type="text" id="sideid"&gt;&lt;/input&gt;
   Length: &lt;input type="text" id="sideid1"&gt;&lt;/input&gt;
   &lt;button onclick="call();"&gt;area of square&lt;/button&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>with the above code am getting response as null. The same code working on IE but not in mozilla...</p>
  
  <p>my webservice side am getting the following error</p>
  
  <pre><code> com.sun.xml.internal.ws.transport.http.server.WSHttpHandler handleExchange
   WARNING: Cannot handle HTTP method: OPTIONS
  </code></pre>
  
  <p>Please Help me out..Thanks in advance</p>